forEach vs forEach.values vs for loop

Benchmark created on


Setup

var count = 10000*1000;

Test runner

Ready to run.

Testing in
TestOps/sec
forEach
const array = []
for(let i = 0; i < count ; i++) {
	array[i] = i;
}

array.forEach(v => v);
ready
forEach.values
const array = []
for(let i = 0; i < count ; i++) {
	array[i] = i;
}

array.values().forEach(v => v);
ready
forEach.values predefined array
const array = new Array(count)
for(let i = 0; i < count ; i++) {
	array[i] = i;
}

array.values().forEach(v => v);
ready
for loop
const array = new Array(count)
for(let i = 0; i < count ; i++) {
	array[i] = i;
}

for(let i = 0; i < count ; i++) {
	let v = array[i]
}
ready

Revisions

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