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,
  sumWhile = 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];
    }
  • while

     
    var l = arr.length;
    var i = 0;
    while (i < l) {
      sumWhile += arr[i];
      i++;
    }
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    forEach
    reduce
    map
    filter
    for
    while

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 3 years ago)
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36
Chrome 93 on Mac OS X 10.15.7
View result in a separate tab
Test name Executions per second
forEach 347.7 Ops/sec
reduce 348.9 Ops/sec
map 336.4 Ops/sec
filter 339.4 Ops/sec
for 298.6 Ops/sec
while 381.9 Ops/sec