Sugar vs Underscore!

JavaScript performance comparison

Revision 9 of this test case created

Info

What's faster?

I really like Sugar.JS however Underscore.js is very popular and seems to have stronger following. Now it's time to see which is faster!

This is silly test that compares only #map() inplementation.

Preparation code

<script src="//underscorejs.org/underscore-min.js"></script>
<script src="//sugarjs.com/current/sugar-full.min.js"></script>
<script src="//rawgit.com/dtao/lazy.js/master/lazy.js"></script>
<script src="//rawgit.com/lodash/lodash/master/dist/lodash.min.js"></script>
<script>var lo = _.noConflict();</script>
 
<script>
Benchmark.prototype.setup = function() {
    window.arrayForSort = [0, 3, 1, 6, 9, 34, 3, 34, 32, 234, 3424, 234, 234, 56, 67, 29, 26, 521, 37, 23, 46, 73, 23, 32, 234, 7, 1];
   
    window.mapFn = function(x) {
      return x * 2
    };
};

Benchmark.prototype.teardown = function() {
    var expectedResult = [0, 6, 2, 12, 18, 68, 6, 68, 64, 468, 6848, 468, 468, 112, 134, 58, 52, 1042, 74, 46, 92, 146, 46, 64, 468, 14, 2];
   
   
    if (!Object.equal(result, expectedResult))
      throw "Result is wrong: " + result;
};
</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
Underscore (_.map)
window.result = _.map(arrayForSort, mapFn);
pending…
Sugar ([].map)
window.result = arrayForSort.map(mapFn);
pending…
Vanilla: for + fn()
window.result = [];
var i;
for (i = 0; i < arrayForSort.length; i++) {
  result[i] = mapFn(arrayForSort[i]);
}
pending…
Vanilla: for
window.result = [];
var i;
for (i = 0; i < arrayForSort.length; i++) {
  result[i] = arrayForSort[i] * 2;
}
pending…
Lazy.js (.map)
window.result = Lazy(arrayForSort).map(mapFn).toArray();
 
pending…
Lodash (_.map)
window.result = lo.map(arrayForSort, mapFn);
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