For vs For..of vs forEach (v4)

Revision 4 of this benchmark created on


Setup

let list = [];
var x = 0;

for (let i = 0; i < 10000; i++) {
	list.push(i);
}

Teardown

x = undefined;

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...in
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.