Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
flatMap vs reduce vs map
(version: 6)
Comparing performance of:
reduce vs flatMap vs map vs foreach vs for of
Created:
one year ago
by:
Registered User
Jump to the latest result
Script Preparation code:
var arr = Array(100).fill({ portfolios: Array(100).fill(null) });
Tests:
reduce
arr.reduce((acc, x) => {acc.push(...x.portfolios); return acc;}, [])
flatMap
arr.flatMap(x => x.portfolios)
map
arr.map(x => x.portfolios).flat()
foreach
const result = []; arr.forEach(x => result.push(...x.portfolios));
for of
const result = []; for(const x of arr) result.push(...x.portfolios);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (5)
Previous results
Fork
Test case name
Result
reduce
flatMap
map
foreach
for of
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36 Edg/134.0.0.0
Browser/OS:
Chrome 134 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
reduce
26163.3 Ops/sec
flatMap
10371.4 Ops/sec
map
10777.5 Ops/sec
foreach
26271.8 Ops/sec
for of
27676.5 Ops/sec
Related benchmarks:
reduce vs flatMap vs map test
reduce vs flatMap test
reduce vs flatMap test2
flatMap vs reduce using push spread vs map flat
flat vs flatMap vs reduce
flatMap vs reduce(push)
flatMap vs reduce without spread
flatMap vs reduce Saran
flatmap vs reduce test
Comments
Confirm delete:
Do you really want to delete benchmark?