for vs while loops, positive and negative (v2)

Revision 2 of this benchmark created on


Setup

const array = Array(500000)
	.fill(null)
    .map((_, i) => i);

Test runner

Ready to run.

Testing in
TestOps/sec
for loop, negative
const length = array.length - 1;

for (let index = length; index > 0; index--) {
	const temp = array[index];
}
ready
while loop
let length = array.length - 1;

while (length) {
	const temp = array[length--];
}
ready
for loop, positive
const length = array.length - 1;

for (let index = 0; index < length; index++) {
	const temp = array[index];
}
ready

Revisions

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