Tests:
  • foreach

    x
     
    const items = Array.from({length: 1000}, () => Math.floor(Math.random() * 40));
    let index = 0;
    items.forEach(i => index++);
  • for-in

     
    const items = Array.from({length: 1000}, () => Math.floor(Math.random() * 40));
    let index = 0;
    for (let i in items) {
        index++;
    }
  • for-of

     
    const items = Array.from({length: 1000}, () => Math.floor(Math.random() * 40));
    let index = 0;
    for (let i of items) {
        index++;
    }
  • for

     
    const items = Array.from({length: 1000}, () => Math.floor(Math.random() * 40));
    let index = 0;
    for(let i = 0; i < items.length; ++i) {
      index++;
    }
  • optimized-for

     
    const items = Array.from({length: 1000}, () => Math.floor(Math.random() * 40));
    let index = 0;
    for(let i = items.length; i > 0; --i) {
      index++;
    }
  • reduce

     
    const items = Array.from({length: 1000}, () => Math.floor(Math.random() * 40));
    items.reduce((acc,value) => {
        acc.push(value);
        return acc;
    }, new Array());
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    foreach
    for-in
    for-of
    for
    optimized-for
    reduce

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 7 months ago)
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36
Chrome 127 on Windows
View result in a separate tab
Test name Executions per second
foreach 5260.1 Ops/sec
for-in 5135.1 Ops/sec
for-of 5464.9 Ops/sec
for 5541.6 Ops/sec
optimized-for 5567.5 Ops/sec
reduce 5309.9 Ops/sec