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 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36
Browser:
Chrome 129
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
reduce
15941.9 Ops/sec
flatMap
21281.6 Ops/sec
flat
21071.1 Ops/sec
reduce push
21219.1 Ops/sec
forEach push
21087.2 Ops/sec
concat spread
236151.8 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)