Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
Feature Requests
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
Benchmark engine:
Benchmark.js
reduce
18.4M/s
flatMap
2.6M/s
View exact numbers
Test name
Executions per second
✓
reduce
18,423,534 Ops/sec
flatMap
2,579,714 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] : []);