For loop comparison (v2)

Revision 2 of this benchmark created on


Setup

const array = new Array(10000000).fill(0).map((_, index) => index);

Test runner

Ready to run.

Testing in
TestOps/sec
Classic for loop
let a = 0;
const len = array.length;
for (let i = 0; i < len; i++) {
	a = array[i];
}
ready
For - of loop
let a = 0;
for (const el of array) {
	a = el; 
}
ready
for - in loop
let a = 0;
for (const index in array) {
	a = array[index];
}
ready
forEach loop
let a = 0;
array.forEach((el) => { a = el });
ready
Classic for loop no uncached length
let a = 0;
for (let i = 0; i < array.length; i++) {
	a = array[i];
}
ready

Revisions

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