filter vs flatmap

Benchmark created on


Setup

const entries = Array.from({length: 100}, (_, idx) => idx)

const EMPTY_ARRAY = []

Test runner

Ready to run.

Testing in
TestOps/sec
flatMap using new empty array
entries.flatMap((e) => e % 2 === 0 ? e : [])
ready
flatMap using EMPTY_ARRAY const
entries.flatMap((e) => e % 2 === 0 ? e : EMPTY_ARRAY)
ready
filter
entries.filter((e) => e % 2 === 0)
ready

Revisions

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