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;
    let array = window.array;
    let len = array.length;
    for (let i = 0; i < len; i++) {
      if (array[i] === 3) {
        x++;
      }
    }
    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: one year ago)
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36
Chrome 118 on Windows
View result in a separate tab
Test name Executions per second
Filter length 2962305.8 Ops/sec
Sum 3481808.5 Ops/sec
Manual 12720138.0 Ops/sec