Tests:
  • foreach

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

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

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

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

     
    const items = Array.from({length: 10}, () => Math.floor(Math.random() * 40));
    let index = 0;
    for(let i = items.length; i > 0; --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
    optimized-for

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: one year ago)
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:48.0) Gecko/20100101 Firefox/48.0
Firefox 48 on Mac OS X 10.6
View result in a separate tab
Test name Executions per second
foreach 157075.2 Ops/sec
for-in 88800.1 Ops/sec
for-of 160777.2 Ops/sec
for 198278.4 Ops/sec
optimized-for 212082.1 Ops/sec