Array Sum: Reduce vs Loop

Benchmark published by System on

Description

Summing numbers in an array.

Setup

const arr = Array.from({length: 10000}, (_, i) => i);

Test Runner

Initializing...

Testing in
Test CaseOps/sec
Array.reduce
const sum = arr.reduce((acc, val) => acc + val, 0);
ready
for loop
let sum = 0;
for(let i=0; i<arr.length; i++) sum += arr[i];
ready

Revisions

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

Revision 1
publishedby Systemon