filter vs foreach if

Benchmark created on


Setup

const a = [undefined, ...Array(155).keys(), null]

Teardown

console.log(a)

Test runner

Ready to run.

Testing in
TestOps/sec
filter
a.filter(i => i).forEach(i => console.log(i))
ready
if
a.forEach(i=> {
	if (i){
		console.log(i)
	}
})
ready

Revisions

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