unique: angular-filter vs lodash

Benchmark created by Ariel Mashraki on


Preparation HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-filter/0.4.7/angular-filter.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/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

Revisions

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