filter(Boolean) vs filter(item => item != null) (v2)

Revision 2 of this benchmark created on


Setup

const maybeNumbers = [];
for (i = 0; i < 1000; i++) {
	if (Math.random() > 0.5) {
		maybeNumbers.push(10 * Math.random() | 0)
	} else {
		maybeNumbers.push(null);
	}
}

Test runner

Ready to run.

Testing in
TestOps/sec
filter(Boolean)
const numbers = maybeNumbers.filter(Boolean);
ready
filter(item => item != null)
const numbers = maybeNumbers.filter(item => item != null);
ready
filter(isDefined)
function isDefined(item) {
	return item != null;
}

const numbers = maybeNumbers.filter(isDefined);
ready

Revisions

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