coffeescript-vs-underscore-vs-lodash

JavaScript performance comparison

Revision 9 of this test case created

Info

Let's compare to naive methods too :)

Preparation code

<script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.4/underscore-min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/1.3.1/lodash.min.js"></script>
<script>
var lodash = _.noConflict();
</script>
<script>
Benchmark.prototype.setup = function() {
    var x = 'x';
    var array = Array(31).join(x).split('');
   
    var _ = window._;
    var _chaining = _(array).chain();
   
    var lodash = window.lodash;
    var lodashChaining = _(array);
   
   
};
</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
Cofffeescript
//coffee -ep "result = (item for item in array when item is x)" 
  var result;

  result = (function() {
    var _i, _len, _results;

    _results = [];
    for (_i = 0, _len = array.length; _i < _len; _i++) {
      item = array[_i];
      if (item === x) {
        _results.push(item);
      }
    }
    return _results;
  })();
pending…
Underscore
var result = _.filter(array, function(value) {
  return value == x;
});
pending…
Underscore w/ Chaining
var result = _chaining.filter(function(value) {
  return value == x;
});
pending…
Lo-Dash
var result = lodash.filter(array, function(value) {
  return value == x;
});
pending…
Lo-Dash w/ Chaining
var result = lodashChaining.filter(function(value) {
  return value == x;
});
pending…
native browser impl...
var result = array.filter(function(value) {
  return value == x;
});
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