Sugar.JS 1.2.5 vs Underscore

JavaScript performance comparison

Revision 3 of this test case created

Preparation code

<script src="https://raw.github.com/documentcloud/underscore/master/underscore-min.js">
</script>
<script src="https://github.com/andrewplummer/Sugar/raw/master/release/1.2.5/minified/sugar-1.2.5.min.js">
</script>
<script>
  function clone(obj) {
    var target = {};
    for (var i in obj) {
      if (obj.hasOwnProperty(i)) {
        target[i] = obj[i];
      }
    }
    return target;
  }

  function merge(destination, source) {
    for (var i in source) {
      if (source.hasOwnProperty(i)) {
        destination[i] = source[i];
      }
    }
    return destination;
  }
</script>
<script>
Benchmark.prototype.setup = function() {
    o = {
      a: 1,
      b: 2,
      c: 3,
      d: 4,
      e: {
        a: 1,
        b: 2,
        c: 3,
        d: 4
      },
      f: {
        a: 1,
        b: 2,
        c: 3,
        d: 4
      },
      g: [{
        a: 1,
        b: 2,
        c: 3,
        d: 4
      }, {
        a: 1,
        b: 2,
        c: 3,
        d: 4
      }]
    }
   
    u = {
      foo: 'bar',
      baz: 'trololo'
    }
};
</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.extend
var foo = _.extend({}, o);
pending…
Sugar.js Object.merge
var foo = Object.merge(u, o);
pending…
Built-In Merge
var foo = merge(u, o);
pending…
Underscore.clone
var foo = _.clone(o);
pending…
Sugar.js Object.clone
var foo = Object.clone(o);
pending…
Built-In Clone
var foo = clone(o);
pending…
Underscore.keys
var foo = _.keys(o);
pending…
Sugar.js Object.keys
var foo = Object.keys(o);
pending…
Underscore.each
_.each(o, function(v) {
  var foo = v;
});
pending…
Sugar.js Object.each
Object.each(o, function(v) {
  var foo = v;
});
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:

1 comment

tomByrer commented :

Tested the lowdash.keys here: http://jsperf.com/keys-underscore-low-dash-sugar/

Add a comment