Script Preparation code:
AخA
 
var arr = [];
for (var i = 0; i < 50000; i++) {
  arr.push(i);
}
Tests:
  • forEach

     
    var objForEach = {};
    arr.forEach(item => {
      objForEach[item] = { exists: true };
    });
  • reduce

     
    var objReduce = arr.reduce((acc, item) => {
      acc[item] = { exists: true };
      return acc;
    }, {});
  • for

     
    var objFor = {};
    for (var j = 0; j < arr.length; j++) {
      var item = arr[j];
      objFor[item] = { exists: true };
    }
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    forEach
    reduce
    for

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 5 years ago)
Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.122 Safari/537.36
Chrome 81 on Windows 7
View result in a separate tab
Test name Executions per second
forEach 86.2 Ops/sec
reduce 106.1 Ops/sec
for 17.0 Ops/sec