for-vs-foreach

Benchmark created on


Setup

const loop = 1000000;
const list = []
for (let i=0; i<loop; ++i)
  list.push(i);

Test runner

Ready to run.

Testing in
TestOps/sec
for
for(let i=0,length=list.length; i<length; ++i)
  list[i] *= 2;
ready
foreach
list.forEach((n, i) => {
  list[i] *= 2;
});
ready

Revisions

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