Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
flatMap() vs filter().map() vs reduce() push vs reduce() spread
flatMap vs filter map vs reduce()
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (X11; Linux x86_64; rv:137.0) Gecko/20100101 Firefox/137.0
Browser:
Firefox 137
Operating system:
Linux
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
filter().map()
442.4 Ops/sec
flatMap()
1115.1 Ops/sec
reduce() push
2252.2 Ops/sec
reduce() spread
15.5 Ops/sec
Script Preparation code:
var arr = []; var i = 0; while (i <= 1E5) arr[i] = i++; var short = arr.filter(x => x <= 1e4);
Tests:
filter().map()
arr.filter(x => x % 12).filter(x => x % 5).filter(x => x % 3).map(x => x/100)
flatMap()
arr.flatMap(x => x % 12 && x % 5 && x % 3 ? x/100 : [])
reduce() push
arr.reduce((newArray, x) => { if (x % 12 && x % 5 && x % 3) { newArray.push(x / 100) } return newArray }, [])
reduce() spread
short.reduce((newArray, x) => { if (x % 12 && x % 5 && x % 3) { return [...newArray, x / 100] } return newArray }, [])