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:
  • .forEach

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

     
    const array = generateTestArray();
    for(const x of array) {
        x.r = x.a + x.b;
    }
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    .forEach
    for..of

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 3 months ago)
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36
Chrome 132 on Windows
View result in a separate tab
Test name Executions per second
.forEach 15.5 Ops/sec
for..of 22.1 Ops/sec