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 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36 Edg/142.0.0.0
Browser:
Chrome 142
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
5 months ago
reduce()
23K/s
filter().map()
20K/s
flatMap()
13K/s
forof loop
2K/s
View exact numbers
Test name
Executions per second
✓
reduce()
23,282 Ops/sec
filter().map()
20,447 Ops/sec
flatMap()
13,256 Ops/sec
forof loop
1,981 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) } }