reduce vs for-loop

Benchmark created on


Setup

const foo = Array.from({ length: 1000 }, (v, k) => k);

Test runner

Ready to run.

Testing in
TestOps/sec
reduce
const result = foo.reduce((acc, v) => acc + v, 0);
console.log(result);
ready
for-loop
let result = 0;

for (const n of foo) {
	result += n;
}
ready

Revisions

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