Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
filter-map vs reduce vs reduce with destructuring 2
modified version of `map-filter vs reduce` that switches the order of operations
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/141.0.0.0 Safari/537.36
Browser:
Chrome 141
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
6 months ago
Test name
Executions per second
map-filter
38933.5 Ops/sec
reduce
43072.5 Ops/sec
reduce with desctructuring
6429.1 Ops/sec
Script Preparation code:
a = []; for (i = 0; i < 1000; i++) a.push(Number(i) / 1000); var filtering = x => (x * 114514) % 1 > 0.5; var mapping = x => x + 0.1919; var reducing = (acc, x) => { if (filtering(x)) acc.push(mapping(x)); return acc; } var reducingWithDestructuring = (acc, x) => { if (filtering(x)) { return [...acc, mapping(x)]; } return acc; }
Tests:
map-filter
a.filter(filtering).map(mapping);
reduce
a.reduce(reducing,[]);
reduce with desctructuring
a.reduce(reducingWithDestructuring,[]);