filter + map vs reduce (v2)

Revision 2 of this benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
filter + map
[1,2,3,4]
	.filter((i) => i % 2 === 0)
	.map((i) => i * 2);
ready
reduce
[1,2,3,4]
	.reduce((acc, i) => {
		if (i % 2 === 0) acc.push(i * 2);
		return acc;
	}, []);
ready
filter + map (long)
Array.from(Array(1000).keys())
	.filter((i) => i % 2 === 0)
	.map((i) => i * 2);
ready
reduce (long)
Array.from(Array(1000).keys())
	.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.