Script Preparation code:
x
 
let items = [];
for (let i = 0; i < 100; i++) {
    items.push({
        something: i
    });
}
window.items = items;
Tests:
  • forEach

     
    let items = window.items;
    let theThing;
    items.forEach(i => {
        let item = i.something;
        if (theThing || i === 3) {
            theThing = i + 3;
        }
    });
    return theThing;
  • Cache len

     
    let items = window.items;
    let theThing;
    let len = items.length;
    for (let i = 0; i < len; i++) {
        let item = items[i].something;
        if (theThing || item === 3) {
            theThing = item + 3;
        }
    }
    return theThing;
  • No cache len

     
    let items = window.items;
    let theThing;
    for (let i = 0; i < items.length; i++) {
        let item = items[i];
        if (theThing || item === 3) {
            theThing = item + 3;
        }
    }
    return theThing;
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    forEach
    Cache len
    No cache len

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 2 years ago)
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36
Chrome 110 on Mac OS X 10.15.7
View result in a separate tab
Test name Executions per second
forEach 3080609.0 Ops/sec
Cache len 5069695.0 Ops/sec
No cache len 3258731.5 Ops/sec