Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
forEach vs reduce vs whatever
(version: 1)
Comparing performance of:
forEach vs reduce vs reduce spread
Created:
3 months ago
by:
Guest
Go to the latest result
Script Preparation code:
var a = Array.from({length:100},()=>Math.random()); var b = [];
Tests:
forEach
let b = []; for (let i = 0; i < a.length; i++) { b.push(a[i]) }
reduce
b = a.reduce((a,c)=>c>0.5?a.concat(c):a,[])
reduce spread
b = a.reduce((a,c)=>c>0.5?[...a,c]:a,[])
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
forEach
reduce
reduce spread
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
3 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:150.0) Gecko/20100101 Firefox/150.0
Browser/OS:
Firefox 150 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
forEach
1.8M/s
reduce
221K/s
reduce spread
44K/s
View exact numbers
Test name
Executions per second
✓
forEach
1,802,942 Ops/sec
reduce
220,613 Ops/sec
reduce spread
44,334 Ops/sec
Related benchmarks
forEach vs reduce
Reduce vs push
Reduce: concat vs push
set vs array iteration for,for-of and values v3
Performance of JavaScript .reduce vs. for vs. for..of
Comments
Confirm delete:
Do you really want to delete benchmark?