filter/map/filter vs for each (v2)

Revision 2 of this benchmark created on


Setup

const xs = new Array(100_000).fill(0).map(i => ({filterOut1: i % 3 === 0, filterOut2: i % 2 === 0, value: i}));

Test runner

Ready to run.

Testing in
TestOps/sec
filter/map/filter
xs
	.filter(x => !x.filterOut1)
	.map(x => ({...x, value2: x.value ** 2}))
	.filter(x => !x.filterOut2)
ready
for each
const out = []

for (const x of xs) {
	if (x.filterOut1) {
		continue;
	}
	if (x.filterOut2) {
		continue;
	}
	out.push({...x, value2: x.value ** 2})
}
ready

Revisions

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