reduce vs +=

Benchmark created on


Setup

const arr = Array(10_000).fill(0)

Test runner

Ready to run.

Testing in
TestOps/sec
Reduce
arr.reduce((acc, n) => acc + n, 0);
ready
+=
let res = 0;
for (const x of arr) res += x;
ready
Simple for +=
let res = 0;
const len = arr.length;
for (let i = 0; i < len; ++i) res += arr[i];
ready

Revisions

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