filter vs compact
Date tested:
4 months ago
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
Test name
Executions per second
lodash filter
3352925.8 Ops/sec
lodash compact
5527962.0 Ops/sec
Native filter
7281668.0 Ops/sec
Benchmark definition (click to collapse):
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/lodash/4.16.0/lodash.min.js"></script>
Script Preparation code:
var ops = [null, 1, 2, 3, 4, 5, null, null, null, 3, 4,5, 6, 34,341,2,2,2,1,212,21212,34,1,3112, null];
Tests:
lodash filter
_.filter(ops, op => !!op)
lodash compact
_.compact(ops)
Native filter
ops.filter(op => !!op)
Open this result on MeasureThat.net