array loop test

Benchmark created on


Setup

const things = Array.from(Array(1000000).keys())

Test runner

Ready to run.

Testing in
TestOps/sec
New For
let countFor = 0;
console.time('for');
for (const thing of things) {
	countFor = countFor + thing;
}

ready
Old For

let countOldFor = 0;
console.time('oldfor');
for (let i = 0; i < things.length; i++) {
	countOldFor = countOldFor + things[i];
}

ready
forEach

let countForEAch = 0;
console.time('foreach')
things.forEach((thing) => {
	countForEAch = countForEAch + thing;
});


ready
Map
let mapCount = 0;
console.time('map')
things.map((thing) => {
	mapCount = mapCount + thing;
});
ready
Reduce
let count = 0;
console.time('reduce')
things.reduce((count, thing) => {
	count = count + thing;
});
ready

Revisions

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