Loop for with and without caching the array length

Benchmark created on


Setup

const myArray = [];
for (let index = 0; index < 1000; index++) {
	myArray[index] = Math.floor(Math.random() * 1000)    
}

Test runner

Ready to run.

Testing in
TestOps/sec
no cache
const result = [];
for (let i = 0; i < myArray.length; i++) {
	result.push(myArray[i]);
}
console.log(result.toString());
ready
cache
const result = [];
for (let i = 0, len = myArray.lenght; i < len; i++) {
	result.push(myArray[i]);
}
console.log(result.toString());
ready

Revisions

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