Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
flatMap vs reduce (concat) vs reduce (spread) vs reduce (push)
(version: 0)
Comparing performance of:
Reduce concat vs FlatMap vs Reduce push vs Reduce spread
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var arr = Array(10000).fill(1)
Tests:
Reduce concat
arr.reduce((acc, x, index) => acc.concat(x, index % 2 ? x : []), [])
FlatMap
arr.flatMap((x, index) => [x, index % 2 && x]).filter(Boolean)
Reduce push
arr.reduce((acc, x, index) => { acc.push(x); if(index % 2) { acc.push(x) } return acc; }, [])
Reduce spread
arr.reduce((acc, x, index) => index % 2 ? [x,...acc] : acc, [])
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
Reduce concat
FlatMap
Reduce push
Reduce spread
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36
Browser/OS:
Chrome 122 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Reduce concat
7.0 Ops/sec
FlatMap
2298.1 Ops/sec
Reduce push
27183.3 Ops/sec
Reduce spread
28.1 Ops/sec
Related benchmarks:
flatMap vs reduce using push
flatMap vs reduce using push spread
flat map vs reduce concat for real
Reduce Push vs. flatMap with subarrays
flatMap vs reduce flattern array
Comments
Confirm delete:
Do you really want to delete benchmark?