Comparing Array Sum Methods

Benchmark created on


Setup

let arr = []

for (let i = 0; i <10000; i++){
	arr[i] = i
}

Test runner

Ready to run.

Testing in
TestOps/sec
Using a for loop
let sum = 0
for(let i =0; i<arr.lenght;i++){
	sum += arr[i]
}
ready
Using Array.reduce
let sum = arr.reduce(function(acc, val) {acc+val}, 0)
ready
Using Array.reduce
let sum = arr.reduce((acc, val)=> acc+val, 0)
ready

Revisions

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