Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
flat vs flatMap vs reduce vs reduce push vs forEach push vs concat spread
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:132.0) Gecko/20100101 Firefox/132.0
Browser:
Firefox 132
Operating system:
Mac OS X 10.15
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
reduce
6238.6 Ops/sec
flatMap
34931.6 Ops/sec
flat
35017.6 Ops/sec
reduce push
86439.7 Ops/sec
forEach push
91594.1 Ops/sec
concat spread
142114.0 Ops/sec
Script Preparation code:
var arr = Array(100).fill(Array(20).fill(Math.random()*50))
Tests:
reduce
arr.reduce((acc, val) => acc.concat(val), [])
flatMap
arr.flatMap(x => x)
flat
arr.flat()
reduce push
arr.reduce((acc, val) => { if (val) val.forEach(a => acc.push(a)); return acc; }, [])
forEach push
let acc = []; arr.forEach(val => { val && val.forEach(v => acc.push(v)); }), acc;
concat spread
[].concat(...arr)