Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
flatMap() vs filter().map() vs reduce() vs forOf loop v8
flatMap vs filter map vs reduce() vs forOf loop
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (X11; Linux x86_64; rv:148.0) Gecko/20100101 Firefox/148.0
Browser:
Firefox 148
Operating system:
Linux
Device Platform:
Desktop
Date tested:
4 months ago
reduce()
24K/s
filter().map()
15K/s
flatMap()
10K/s
forof loop
6K/s
View exact numbers
Test name
Executions per second
✓
reduce()
23,725 Ops/sec
filter().map()
14,592 Ops/sec
flatMap()
10,223 Ops/sec
forof loop
5,790 Ops/sec
Script Preparation code:
var arr = []; var i = 0; while (i <= 10000) arr[i] = i++;
Tests:
filter().map()
arr.filter(x => x % 2).map(x => x/100)
flatMap()
arr.flatMap(x => x % 2 ? x/100 : [])
reduce()
arr.reduce((newArray, x) => { if (x % 2) { newArray.push(x / 100) } return newArray }, [])
forof loop
newArray = []; for (x of arr){ if (x % 2) { newArray.push(x / 100) } }