For vs For..of vs forEach (v3)

Revision 3 of this benchmark created on


Setup

const list = [];
let x;

for (let i = 0; i < 10000; 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
For...of
for (const item in list) {
	x = item;
}
ready

Revisions

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