For loops

Benchmark created on


Setup

const data = new Array(1000).fill(0).map((v) => v + 1);

Test runner

Ready to run.

Testing in
TestOps/sec
prefix without length cache
let sum = 0;
	
for (let i = 0; i < data.length; ++i) {
	sum += data[i];
}
ready
prefix with length cache
let sum = 0;
	
for (let i = 0, l = data.length; i < l; ++i) {
	sum += data[i];
}
ready
postfix without length cache
let sum = 0;
	
for (let i = 0; i < data.length; i++) {
	sum += data[i];
}
ready
postfix with length cache
let sum = 0;
	
for (let i = 0, l = data.length; i < l; i++) {
	sum += data[i];
}
ready
increment withouth length cache
let sum = 0;
	
for (let i = 0; i < data.length; i += 1) {
	sum += data[i];
}
ready
increment with length cache
let sum = 0;
	
for (let i = 0, l = data.length; i < l; i += 1) {
	sum += data[i];
}
ready

Revisions

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