for & forEach

Benchmark created on


Description

for & forEach

Setup

// 1000000 items in array 
const array = new Array(1000000).fill(0);

function f() {
  for (let i = 0; i < array.length; i++) {
    const item = array[i];
    console.log(i, item);
  }
}

function f2() {
  array.forEach((item, i) => {
    console.log(i, item);
  });
}

Test runner

Ready to run.

Testing in
TestOps/sec
for
f()
ready
forEach
f2()
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.