Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
flatMap() vs filter().map() vs for loop accumulator vs forEach vs for of loop
(version: 1)
flatMap vs filter map
Comparing performance of:
filter().map() vs flatMap() vs for loop vs forEach vs for of loop
Created:
one year ago
by:
Guest
Jump to the latest result
Script Preparation code:
var arr = []; var i = 0; while (i <= 1E5) arr[i] = i++;
Tests:
filter().map()
arr.filter(x => x % 30).map(x => x/100)
flatMap()
arr.flatMap(x => x % 30 ? x/100 : [])
for loop
var accum = []; for (let i=0; i < arr.length; i++) { const x = arr[i]; if (x % 30) { accum.push(x/100) } }
forEach
var accum = []; arr.forEach((x) => { if (x % 30){ accum.push(x/100) } })
for of loop
var accum = []; for (const x of arr) { if (x % 30) { accum.push(x/100) } }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (5)
Previous results
Fork
Test case name
Result
filter().map()
flatMap()
for loop
forEach
for of loop
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36
Browser/OS:
Chrome 135 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
filter().map()
263.9 Ops/sec
flatMap()
267.7 Ops/sec
for loop
503.8 Ops/sec
forEach
349.5 Ops/sec
for of loop
518.6 Ops/sec
Related benchmarks:
flatMap() vs filter().map()
flatMap() vs map().filter()
flatMap() vs filter().map() vs for loop accumulator
flatMap() vs filter().map() vs reduce vs for
Array flatMap() vs filter().map()
flatMap() vs filter().map() vs foreach and push
flatMap() vs filter().map() vs for..of
flatMap() vs filter().map() 1
flatMap() vs filter().map() vs for loop accumulator vs forEach
Comments
Confirm delete:
Do you really want to delete benchmark?