For loop vs .reduce

Benchmark created on


Setup


// Create a million random numbers
const values = new Array(1_000_000).fill(true).map(() => Math.random()); 

Test runner

Ready to run.

Testing in
TestOps/sec
for loop
let result = 0; 

for(let i of values){
	result += i; 
}
ready
reduce
const result = values.reduce((acc,cur) => {
	return acc + cur; 
},0)
ready

Revisions

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