Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
JS for loop vs Array.reduce
(version: 1)
Comparing performance of:
for loop vs Array.reduce
Created:
one year ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<!--your preparation HTML code goes here-->
Script Preparation code:
const values = [5, 0, 0.5, 10, 34, 20, 22, 71, 0, 0, 5.4, 34.3, 56.21]
Tests:
for loop
let sum = 0; for (let i = 0; i < values.length; i++) { sum += values[i]; }
Array.reduce
const sum = values.reduce((acc, val) => acc + val);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
for loop
Array.reduce
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
3 months ago
)
User agent:
Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.75 Safari/537.36
Browser/OS:
Chrome 86 on Windows 7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
for loop
11922552.0 Ops/sec
Array.reduce
41181004.0 Ops/sec
Related benchmarks:
Testing loops performance
Testing loops performance
loop vs reduce for summation
loop vs reduce for sums
Reduce vs For loop in accumulated calculations
for vs reduce freddiekun version 420
Array sum
Sum array: for vs forEach vs for..in vs for..of vs reduce
2Sum array: for vs forEach vs for..in vs for..of vs reduce
Comments
Confirm delete:
Do you really want to delete benchmark?