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

     
    const r = 0;
    for (let i = 0; i < array.length; ++i) {
       r += array[i].a + array[i].b;
    }
  • .reduce

     
    array.reduce((p, x) => p + x.a + x.b, 0);
  • .reduce (destructuring)

     
    array.reduce((p, {a,b}) => p + a + b, 0);
  • for..of (reduce)

     
    let r = 0;
    for (const x of array) {
       r += x.a + x.b;
    }
  • for..of (reduce) (destructuring)

     
    let r = 0;
    for (const {a,b} of array) {
       r += a + b;
    }
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    for
    .reduce
    .reduce (destructuring)
    for..of (reduce)
    for..of (reduce) (destructuring)

    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/135.0.0.0 Safari/537.36
Chrome 135 on Mac OS X 10.15.7
View result in a separate tab
Test name Executions per second
for 183367248.0 Ops/sec
.reduce 53378000.0 Ops/sec
.reduce (destructuring) 61994520.0 Ops/sec
for..of (reduce) 180358480.0 Ops/sec
for..of (reduce) (destructuring) 60718912.0 Ops/sec