Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
Feature Requests
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; rv:131.0) Gecko/20100101 Firefox/131.0
Browser:
Firefox 131
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Benchmark engine:
Benchmark.js
concat spread
246K/s
forEach push
239K/s
reduce push
230K/s
flat
108K/s
flatMap
107K/s
reduce
7K/s
View exact numbers
Test name
Executions per second
✓
concat spread
246,394 Ops/sec
forEach push
239,033 Ops/sec
reduce push
229,928 Ops/sec
flat
107,681 Ops/sec
flatMap
106,580 Ops/sec
reduce
7,460 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)