Tests:
  • foreach

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

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

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

     
    const items = Array.from({length: 500000}, () => Math.floor(Math.random() * 40));
    let index = 0;
    for(let i = 0; i < items.length; ++i) {
        item = items[i]
      index++;
    }
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

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

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 5 months ago)
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36
Chrome 130 on Windows
View result in a separate tab
Test name Executions per second
foreach 6.5 Ops/sec
for-in 3.6 Ops/sec
for-of 7.1 Ops/sec
for 4.7 Ops/sec