Run details:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:133.0) Gecko/20100101 Firefox/133.0
Firefox 133
Mac OS X 10.15
Desktop
2 months ago
Test name Executions per second
Chain 2.1 Ops/sec
Native (with &&) 4.6 Ops/sec
Native 2.4 Ops/sec
Flow 2.1 Ops/sec
Chain (with &&) 4.2 Ops/sec
HTML Preparation code:
AخA
 
1
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
2
<script src='https://cdn.jsdelivr.net/g/lodash@4(lodash.min.js+lodash.fp.min.js)'></script>
Script Preparation code:
 
var data = Array(10000000).fill({ a: 'a', b: 1 });
Tests:
  • Chain

     
    _.chain(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').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

     
    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

     
    _.flow(
      _.filter(f => f.a === 'a'),
      _.filter(f => f.b === 1),
      _.filter(f => f.b + 1 === 2),
      _.map(f => f.a),
      _.filter(f => f === 'a')
    )(data)
  • Chain (with &&)

     
    _.chain(data).filter(f => f.a === 'a' && f.b === 1 && f.b + 1 === 2).map(f => f.a).filter(f => f === 'a').value()