Script Preparation code:
AخA
 
function generateTestArray() {
  const result = [];
  for (let i = 0; i < 1000000; ++i) {
    result.push({
      a: i,
      b: i / 2,
      r: 0,
    });
  }
  return result;
}
Tests:
  • for..of

     
    const array = generateTestArray();
    for(const x of array) {
        x.r = x.a + x.b;
    }
  • .map

     
    const array = generateTestArray();
    array.map(x => x.a + x.b)
  • .for (init array)

     
    const array = generateTestArray();
    const r = new Array(array.length);
    for (let i = 0; i < array.length; ++i) {
       r[i] = array[i].a + array[i].b;
    }
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    for..of
    .map
    .for (init array)

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 2 years ago)
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36
Chrome 111 on Mac OS X 10.15.7
View result in a separate tab
Test name Executions per second
for..of 6.4 Ops/sec
.map 7.2 Ops/sec
.for (init array) 8.5 Ops/sec