filter vs compact

5 months ago
User agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36
Test name Executions per second
lodash filter 2043237.0 Ops/sec
lodash compact 3640652.5 Ops/sec
Native filter 5335408.0 Ops/sec
HTML Preparation code:
AخA
 
1
<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