$.grep vs _.filter

JavaScript performance comparison

Test case created by Adrian

Preparation code

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

<script src="https://raw.github.com/documentcloud/underscore/master/underscore-min.js"></script>

<script src="https://raw.github.com/bestiejs/lodash/v1.0.1/dist/lodash.min.js"></script>

<script>
var lodash = _.noConflict();
</script>
      
<script>
Benchmark.prototype.setup = function() {
  var arr = new Array(1000);

};
</script>

Preparation code output

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
lodash
var evens = lodash.filter(arr, function (num) { 
    return num % 2 == 0; 
});
pending…
jquery
var evens = $.grep(arr, function (num) { 
    return num % 2 == 0; 
});
pending…
underscore
var evens = _.filter(arr, function (num) { 
    return num % 2 == 0; 
});
pending…

Compare results of other browsers

Revisions

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

0 Comments