For vs For..of vs forEach (v2)

Revision 2 of this 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
Array.entries
for (const [index, item] of list.entries())
	x = item;
ready

Revisions

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