Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
reduce vs flatMap, conditional
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36
Browser:
Chrome 110
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
2 years ago
Test name
Executions per second
reduce
18423534.0 Ops/sec
flatMap
2579714.2 Ops/sec
Script Preparation code:
var xs = [{ text: "a", sort: false }, { text: "b", sort: true }, { text: "c", sort: false }, { text: "d", sort: true }, { text: "e", sort: false }]
Tests:
reduce
xs.reduce((acc, x) => { if (x.sort) { acc.push(x.text); } return acc; }, ["z"])
flatMap
xs.flatMap((x) => x.sort ? [x.text] : []);