HTML Preparation code:
AخA
 
1
<script src="https://cdn.jsdelivr.net/lodash/4.16.2/lodash.min.js"></script>
Script Preparation code:
 
window.array = [1, 4, 3, 4, 2, 2, 1, 5, 3, 5, 1, 4, 3, 4, 2, 2, 1, 5, 3, 5, 1, 4, 3, 4, 2, 2, 1, 5, 3, 5, 1, 4, 3, 4, 2, 2, 1, 5, 3, 5, 1, 4, 3, 4, 2, 2, 1, 5, 3, 5];
Tests:
  • Filter length

     
    const x = _.filter(window.array, i => i === 3).length;
    return x;
  • Sum

     
    const x = _.sumBy(window.array, i => i === 3 ? 1 : 0);
    return x;
  • Manual

     
    let x = 0;
    for (let i = 0; i < window.array.length; i = i + 1) {
      if (window.array[i] === 3) {
        x = x + 1;
      }
    }
    return x;
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    Filter length
    Sum
    Manual

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 3 years ago)
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Firefox/78.0
Firefox 78 on Windows
View result in a separate tab
Test name Executions per second
Filter length 1306135.4 Ops/sec
Sum 2000717.6 Ops/sec
Manual 49539.4 Ops/sec