Script Preparation code:
x
 
var arr = [];
for (var i = 0; i < 12345; i++) {
  arr[i] = i;
}
function someFn(i) {
  return (i * 3 * 8 / 1200 * 0.002 / 40 * 0.2);
}
var sumForEach = 0,
  sumReduce = 0,
  sumMap = 0,
  sumFilter = 0,
  sumFor = 0,
  sumForOf =0;
Tests:
  • forEach

     
    arr.forEach(item => sumForEach += someFn(item));
  • reduce

     
    sumReduce = arr.reduce((lastValue, item) => {
      return sumReduce += someFn(item);
    });
  • map

     
    arr.map(item => (sumMap += someFn(item)));
  • filter

     
    arr.filter(item => (sumFilter += someFn(item)));
  • for

     
    for (var j = 0; j < arr.length; j++) {
      sumFor += arr[j];
    }
  • forof

     
    for (let a of arr) {
        sumForOf += a;
    }
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    forEach
    reduce
    map
    filter
    for
    forof

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 4 years ago)
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36
Chrome 83 on Mac OS X 10.15.5
View result in a separate tab
Test name Executions per second
forEach 234.4 Ops/sec
reduce 222.7 Ops/sec
map 212.5 Ops/sec
filter 225.5 Ops/sec
for 203.3 Ops/sec
forof 342.5 Ops/sec