Tests:
  • foreach

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

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

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

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

     
    const items = Array.from({length: 1000}, () => Math.floor(Math.random() * 40));
    let index = 0;
    let i = items.length;
    while (i--) index += items[i];
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

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: one month ago)
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36
Chrome 133 on Windows
View result in a separate tab
Test name Executions per second
foreach 29044.2 Ops/sec
for-in 24133.0 Ops/sec
for-of 36487.3 Ops/sec
for 36439.2 Ops/sec
optimized-for 36760.9 Ops/sec