Sugar vs lo-dash (was Underscore!)

JavaScript performance comparison

Revision 6 of this test case created by Mike

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!

Preparation code

<script src = '//cdnjs.cloudflare.com/ajax/libs/lodash.js/1.3.1/lodash.js'></script>
<script src="//sugarjs.com/current/sugar-full.min.js">
</script>
<script>
  Benchmark.prototype.setup = function() {

     Arr = [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];
Object.keys=Object.keys||function(o,r){r=[];for(r[r.length] in o);return r}
    applier = function(num) {
      return num * 2;
    }
    var containsObj = function (arr) {var x=arr.length; while (x--) {if (typeof arr[x] === 'object') return true } return false;}

    var dullArr = function(arr,p) {var x=arr.length, i=x, cx= true; while(void(arr[i]==undefined?'':cx=false), cx!=false && i--); return cx;};

    var deep = function () {return false;}
  var o = function (o, fn) {
      //  if (containsObj(o)) {return deep(o, fn);}
        var set = function () {var rs=fn(o[i]); typeof rs === 'boolean'?(!!rs?(z.push(o[i])):''):z[i]=rs }
        var i = 0, z =[];
        do set(); while (o[i+=1]);
        return z;
    }

    var y = function (o, fn) {
      var i = 0, z=[], rs;
      //if (containsObj(o)) {return deep();}
      while(void(rs=fn(o[i]), typeof rs === 'boolean'?(!!rs?(z.push(o[i])):''):z[i]=rs), o[i+=1]);
      return z
    }
    map = o,
    wmap=y;

  }
</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
_.map
var result = _.map(Arr, applier)
pending…
Object.map
var result = Object.map(Arr, applier)
pending…
map()
var result = map(Arr, applier)
pending…
wmap()
var result = wmap(Arr, applier)
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