Lodash Chain (v3)

Revision 3 of this benchmark created by Oleg on


Description

Compare chaining lodash functions to multiple function calls on a collection of objects

Preparation HTML

<script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.js"></script>

Setup

var myCollection = [
    { is_active: true, description: 'HazMat', price: 150, information: 'Handling of HazMat', is_required: true },
    { is_active: true, description: 'Stop Off', price: 50, information: 'Stop Off', is_required: true },
    { is_active: true, description: 'Chassis Repositioning', price: 800, information: 'From BNSF and CSX' },
    { is_active: true, description: 'Crosstown', price: 105, information: 'From BNSF to NS Memphis' },
    { is_active: true, description: 'Detention', price: 70, information: 'Per hour' },
    { is_active: true, description: 'Poor chassis', price: 18, information: 'COCP chassis' },
    { is_active: true, description: 'Free time', price: 150, information: '2 hours outshot free drop zone' },
    { is_active: true, description: 'Drop', price: 90, information: 'Double published rate outside of free drop zone' },
    { is_active: true, description: 'Detention', price: 70, information: 'Per hour' }
    ];
    
    var wrapped = _(myCollection);

Test runner

Ready to run.

Testing in
TestOps/sec
Chain
_(myCollection)
  .filter('is_required')
  .pluck('description')
  .contains('Detention')
ready
Chain Pre-wrapped
wrapped
  .filter('is_required')
  .pluck('description')
  .contains('Detention')
ready
Non Chain
var items = _.filter(myCollection, 'is_required');
var descriptions = _.pluck(items, 'description');
var result = _.contains(descriptions, 'Detention');
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.