flatMap vs concat filter map (v2)

Revision 2 of this benchmark created on


Setup

const baseList = Array.from({length: 1000}, (_, idx) => ({value: Math.random(), arrayValues: [Math.random(), Math.random()]}))

const EMPTY_ARRAY = []

Test runner

Ready to run.

Testing in
TestOps/sec
filter + map + concat
[].concat(...baseList.filter((obj) => 
  obj.value > 0.5
).map((obj) => 
  obj.arrayValues
))
ready
flatMap
baseList.flatMap((obj) => 
  obj.value > 0.5 ? obj.arrayValues : EMPTY_ARRAY
)
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.