Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Filter Boolean vs. Custom Function
Testing the performance of the idiomatic .filter(Boolean) vs. filtering by a custom coercing function.
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Android 14; Mobile; rv:129.0) Gecko/129.0 Firefox/129.0
Browser:
Firefox Mobile 129
Operating system:
Android
Device Platform:
Mobile
Date tested:
one year ago
Test name
Executions per second
filter(Boolean)
3823.7 Ops/sec
filter function
4234.8 Ops/sec
Script Preparation code:
var arr = Array.from({length: 10000}, () => Math.random() > 0.5 ? null : "foo");
Tests:
filter(Boolean)
const numTruthy = arr.filter(Boolean).length; console.log(numTruthy);
filter function
const numTruthy = arr.filter(x => !!x).length; console.log(numTruthy);