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++;
    }
  • map

     
    const items = Array.from({length: 1000}, () => Math.floor(Math.random() * 40));
    items.map((_, i)=> i++);
  • reduce

     
    const items = Array.from({length: 1000}, () => Math.floor(Math.random() * 40));
    items.reduce((acc, curr)=> acc++, 0);
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
    map
    reduce

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 4 months ago)
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36
Chrome 130 on Mac OS X 10.15.7
View result in a separate tab
Test name Executions per second
foreach 6291.3 Ops/sec
for-in 6301.2 Ops/sec
for-of 6797.1 Ops/sec
for 6740.6 Ops/sec
optimized-for 6730.4 Ops/sec
map 6687.3 Ops/sec
reduce 6725.1 Ops/sec