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 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36
Browser:
Chrome 134
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
filter().map()
25788.3 Ops/sec
flatMap()
9153.4 Ops/sec
reduce()
15673.1 Ops/sec
forof loop
1284.9 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) } }