Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Calculate sum
(version: 0)
Comparing performance of:
reduce vs for .. of vs forEach vs for
Created:
4 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var arr = [...Array(5000).keys()]
Tests:
reduce
let s = arr.reduce((s, i) => s + i, 0);
for .. of
let s = 0; for(const i of arr) { s += i }
forEach
let s = 0; arr.forEach(i => { s += i })
for
let s = 0; for(let i = 0; i < arr.length; i++) s += arr[i];
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
reduce
for .. of
forEach
for
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Related benchmarks:
sum calculation: forEach vs for vs forof vs reduce 2
for of vs Array.reduce vs Array.forEach vs for i for summing and array of integers
Object.keys.length vs sum with for a
Array.prototype.reduce() vs for loop sum
Comments
Confirm delete:
Do you really want to delete benchmark?