For vs For..of vs forEach

Benchmark created on


Setup

const list = [];
let x;

for (let i = 0; i < 100000; i++)
	list.push(i);

Test runner

Ready to run.

Testing in
TestOps/sec
For
for (let i = 0; i < list.length; i++)
	x = list[i];
ready
For...of
for (const item of list)
	x = item;
ready
forEach
list.forEach(item => x = item);
ready

Revisions

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