filter vs forEach + push

Benchmark created on


Setup

const arr = new Array(10000).fill(0).map(e => Math.random())

Test runner

Ready to run.

Testing in
TestOps/sec
filter
const arr1 = arr.filter(e => e > 0.5)
ready
forEach + push
const arr2 = [];

arr.forEach(e => {
	if (e > 0.5) {
		arr2.push(e);
	}
})
ready

Revisions

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