Script Preparation code:
AخA
 
function generateTestArray() {
  const result = [];
  for (let i = 0; i < 1000000; ++i) {
    result.push(i);
  }
  return result;
}
window.array = generateTestArray();
Tests:
  • map comparison: for..of

     
    const r = [];
    for(const x of array) {
      r.push(x);
    }
  • map comparison: .map

     
    array.map(x => x)
  • reduce comparision: for..of

     
    let r = 0;
    for (const x of array) {
       r += x;
    }
  • reduce comparision: .reduce

     
    array.reduce((p, x) => p + x, 0);
  • raw iteration: for..of

     
    for(const x of array) {}
  • raw iteration: forEach

     
    array.forEach(x => {})
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    map comparison: for..of
    map comparison: .map
    reduce comparision: for..of
    reduce comparision: .reduce
    raw iteration: for..of
    raw iteration: forEach

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: one month ago)
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36
Chrome 133 on Mac OS X 10.15.7
View result in a separate tab
Test name Executions per second
map comparison: for..of 87.6 Ops/sec
map comparison: .map 118.1 Ops/sec
reduce comparision: for..of 135.9 Ops/sec
reduce comparision: .reduce 109.0 Ops/sec
raw iteration: for..of 158.1 Ops/sec
raw iteration: forEach 233.1 Ops/sec