coffeescript-vs-underscore-vs-lodash-vs-jquery

JavaScript performance comparison

Revision 8 of this test case created

Info

Removed chaining tests.

Added jQuery to the test.

More data (1000000 objects).

Use === everywhere.

Updated libs.

Preparation code

<script src="//code.jquery.com/jquery-2.1.0.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.6.0/underscore-min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.min.js"></script>
<script>
var lodash = _.noConflict();
</script>
<script>
Benchmark.prototype.setup = function() {
    var gender = 'male';
    var array = [
        {"gender": "male"},
        {"gender": "female"}
    ];
   
    var _ = window._;
   
    var lodash = window.lodash;
   
    array = _.map(_.range(1000000), function(){
        return {gender: Math.random() > 0.5 ? "male" : "female"};
    });
};
</script>

Preparation code output

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
JS (exposed vars)
var item, result = [];

var i, len;
for (i = 0, len = array.length; i < len; i++) {
  item = array[i];
  if (item.gender === gender) {
    result.push(item);
  }
}
pending…
Underscore
var result = _.filter(array, function(value) {
  return value.gender === gender;
});
pending…
Lo-Dash
var result = lodash.filter(array, function(value) {
  return value.gender === gender;
});
pending…
jQuery
var result = jQuery.grep(array, function(value) {
  return value.gender === gender;
});
pending…
CoffeeScript
var item, result;

result = (function() {
  var _i, _len, _results;
  _results = [];
  for (_i = 0, _len = array.length; _i < _len; _i++) {
    item = array[_i];
    if (item.gender === gender) {
      _results.push(item);
    }
  }
  return _results;
})();
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. Here’s a list of current revisions for this page:

0 comments

Add a comment