Angular VS Underscore Extend

Benchmark created by Shaun on


Preparation HTML

<script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.7.0/underscore-min.js"></script><script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js"></script>

Setup

var emptyObj   = {},
        smallObj   = { size:5  },
        medObj     = { size:25 },
        lrgObj     = { size:50 },
        allObjects = [ emptyObj, smallObj, medObj, lrgObj ];
    
    _.each(_.rest(allObjects), function(obj) {
      _.times(obj.size - 1, function(i) { obj[i] = i + 1; });
    });
    
    function extendWithFn(fn) {
      var result;
      _.each(allObjects, function(destinationObj) {
        _.each(allObjects, function(sourceObj) {
          result = fn({}, destinationObj, sourceObj);
        })
      });
      return result;
    };

Test runner

Ready to run.

Testing in
TestOps/sec
Extend with Angular
extendWithFn(angular.extend);
ready
Extend with Underscore
extendWithFn(_.extend);
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.

  • Revision 1: published by Shaun on