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/126.0.0.0 Safari/537.36
Browser:
Chrome 126
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
reduce
10456.8 Ops/sec
flatMap
20880.8 Ops/sec
flat
22013.4 Ops/sec
reduce push
23379.8 Ops/sec
forEach push
24002.6 Ops/sec
concat spread
216783.3 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)