Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
Feature Requests
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 12; Mobile; rv:130.0) Gecko/130.0 Firefox/130.0
Browser:
Firefox Mobile 130
Operating system:
Android
Device Platform:
Mobile
Date tested:
2 years ago
Benchmark engine:
Benchmark.js
filter function
4K/s
filter(Boolean)
4K/s
View exact numbers
Test name
Executions per second
✓
filter function
4,419 Ops/sec
filter(Boolean)
3,868 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);