Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Filter out null and map nested object with flatMap() vs map().filter()
(version: 5)
flatMap vs filter map
Comparing performance of:
map().filter() vs flatMap() vs filter().map()
Created:
one year ago
by:
Registered User
Jump to the latest result
Script Preparation code:
var arr = []; var id = 0; while (id <= 1_000_000) { id++; arr[id] = id % 10 === 0 ? { id, data: null } : { id, data: { id } }; }
Tests:
map().filter()
arr.map(it => it.data).filter(it => it !== null)
flatMap()
arr.flatMap(it => it.data != null ? [it.data] : [])
filter().map()
arr.filter(it => it.data !== null).map(it => it.data)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
map().filter()
flatMap()
filter().map()
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:138.0) Gecko/20100101 Firefox/138.0
Browser/OS:
Firefox 138 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
map().filter()
16.7 Ops/sec
flatMap()
11.8 Ops/sec
filter().map()
15.2 Ops/sec
Related benchmarks:
flatMap() vs filter().map() vs map().filter(Boolean)
flatMap vs filter&map
filter.map vs flatMap vs reduce performance test
JOSH's flatMap() vs map().filter()
flatMap() vs filter().map() 2234234
flatMap() vs filter().map() Bruno 1111
flatMap() vs filter().map() vs array.reduce
flatMap() vs filter().map() vs map().filter()
flatMap() vs filter().map() 1asdasd
Comments
Confirm delete:
Do you really want to delete benchmark?