mixinspeeds

Benchmark created on


Setup

var giveRights = (function() {
      var vote = function() {
          return 1;
          }
          
          
          
      var age = function() {
          return 2;
          }
          
          
          
      var die = function() {
          return 3;
          }
          
          
          
      return function() {
        this.vote = vote;
        this.age = age;
        this.die = die;
      }
    }());
    
    
    
    var mixObjects = function(obj1, obj2) {
        for (var key in obj2) {
          if (obj2.hasOwnProperty(key)) {
            obj1[key] = obj2[key];
          }
        }
        return obj2;
        }
        
        
        
        
        
    var rights = {
      vote: function() {
        return 1;
      },
      age: function() {
        return 2;
      },
      die: function() {
        return 3;
      }
    }

Test runner

Ready to run.

Testing in
TestOps/sec
Normal Mixin
var slave = function() {};

slave = mixObjects(slave, rights);
ready
Function mixin
var slave = function() {};
giveRights.call(slave);
ready

Revisions

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