Lodash Chain (with &&) vs Native (with &&) vs Native (without &&) vs Flow
Date tested:
2 years ago
User agent:
Mozilla/5.0 (Linux; Android 10; ELE-L29) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Mobile Safari/537.36
Test name
Executions per second
Chain
0.5 Ops/sec
Native (with &&)
0.4 Ops/sec
Native (without &&)
0.2 Ops/sec
Flow
0.3 Ops/sec
Benchmark definition (click to collapse):
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script> <script src='https://cdn.jsdelivr.net/g/lodash@4(lodash.min.js+lodash.fp.min.js)'></script>
Script Preparation code:
var fp = _.noConflict(); var data = Array(10000000).fill({ a: 'a', b: 1 });
Tests:
Chain
_.chain(data).filter(f => f.a === 'a' && f.b === 1 && f.b + 1 === 2).map(f => f.a).filter(f => f === 'a').value()
Native (with &&)
data.filter(f => f.a === 'a' && f.b === 1 && f.b + 1 === 2).map(f => f.a).filter(f => f === 'a')
Native (without &&)
data.filter(f => f.a === 'a').filter(f => f.b === 1).filter(f => f.b + 1 === 2).map(f => f.a).filter(f => f === 'a')
Flow
fp.flow( fp.filter(f => f.a === 'a'), fp.filter(f => f.b === 1), fp.filter(f => f.b + 1 === 2), fp.map(f => f.a), fp.filter(f => f === 'a') )(data)
Open this result on MeasureThat.net