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:
one month ago
by:
Guest
Jump 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:
one month 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
Test name
Executions per second
forEach
1802941.9 Ops/sec
reduce
220613.1 Ops/sec
reduce spread
44333.8 Ops/sec
Related benchmarks:
forEach vs reduce
forEach vs reduce
forEach vs reduce
Reduce vs push
forEach concat vs reduce push vs forEach push vs reduce concat performance
JS For vs reduce
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?