Map & Filter vs FlatMap

Benchmark created on


Setup

const arr = [];
for(let x=0; x<1; x+=0.001){
	arr.push(x);
}

Test runner

Ready to run.

Testing in
TestOps/sec
Map & Filter
arr.filter(x => x<.5).map(x => x*1000);
ready
FlatMap
arr.flatMap((x)=> x<.5?[x*1000]:[]);
ready

Revisions

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