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 (X11; Linux x86_64; rv:123.0) Gecko/20100101 Firefox/123.0
Browser:
Firefox 123
Operating system:
Linux
Device Platform:
Desktop
Date tested:
2 years ago
Test name
Executions per second
reduce
1544.5 Ops/sec
flatMap
40522.2 Ops/sec
flat
43117.9 Ops/sec
reduce push
59881.5 Ops/sec
forEach push
58864.9 Ops/sec
concat spread
65250.6 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)