unique: angular-filter vs lodash (v5)

Revision 5 of this benchmark created on


Preparation HTML

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-filter/0.4.8/angular-filter.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.min.js"></script>
<script src="https://raw.githubusercontent.com/rockabox/ng-lodash/master/build/ng-lodash.min.js"></script>

Setup

var orders = [{
      id: 1,
      customer: {
        name: 'John',
        id: 10
      }
    }, {
      id: 2,
      customer: {
        name: 'William',
        id: 20
      }
    }, {
      id: 3,
      customer: {
        name: 'John',
        id: 10
      }
    }, {
      id: 4,
      customer: {
        name: 'William',
        id: 20
      }
    }, {
      id: 5,
      customer: {
        name: 'Clive',
        id: 30
      }
    }, ];

Test runner

Ready to run.

Testing in
TestOps/sec
unique-angularFilter
angular.module('app', ['angular.filter'])
  .controller('appCtrl', function($scope, $filter) {
    $scope.res = $filter('unique')(players, 'customer.id')
  })
ready
unique-lodashFilter
angular.module('app', [])
  .controller('appCtrl', function($scope, $filter) {
    $scope.res = $filter('unique')(players, 'customer.id')
  })
  .filter('unique', function($parse) {
    return function(input, key) {
      return _.unique(input, function(el) {
        return $parse(key)(el);
      });
    }
  })
ready
unique-ngLodashFilter
angular.module('app', ['ngLodash'])
  .controller('appCtrl', function($scope, $filter, lodash) {
    $scope.res = $filter('unique')(players, 'customer.id')
  })
  .filter('unique', function($parse, lodash) {
    return function(input, key) {
      return lodash.unique(input, function(el) {
        return $parse(key)(el);
      });
    };
  });
ready

Revisions

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