Array.filter vs lodash.filter without bias

Benchmark created on


Description

Test performance of native filter method for arrays vs lodash filter method

Preparation HTML

<script src="//rawgit.com/lodash/lodash/36ba19ed3befcac63e2579cdfbd57168b9b266e8/dist/lodash.js"></script>

Setup

var a1 = _.range(100);
    
    var a2 = _.union.apply(_, _.times(34, function() {
      return [
        { name: 'john', age: 47 },
        { name: 'jane', age: 22 },
        { name: 'bill', age: 60 }
      ];
    }));

Test runner

Ready to run.

Testing in
TestOps/sec
lodash filter
var r1 = _.filter(a1, function (n) { return n % 2 === 0; });

var r2 = _.filter(a2, function (person) { return person.age > 50; });
ready
Array.filter
var r1 = a1.filter(function (n) { return n % 2 === 0; });

var r2 = a2.filter(function (person) { return person.age > 50; });
ready

Revisions

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