filter + map vs reduce

Benchmark created on


Setup

const input = Array.from(Array(100).keys());

Test runner

Ready to run.

Testing in
TestOps/sec
filter + map
input
	.filter((i) => i % 2 === 0)
	.map((i) => i * 2);
ready
reduce
input
	.reduce((acc, i) => {
		if (i % 2 === 0) acc.push(i * 2);
		return acc;
	}, []);
ready

Revisions

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