Object.create vs Crockford vs Constructor (v63)

Revision 63 of this benchmark created by carlesba on


Preparation HTML

<script>
  var sharedPrototype = {
   one: function() {
    return 1;
   },
   two: function() {
    return 2;
   },
   three: function() {
    return 3;
   }
  };
  
  var crockfordCreate = function(proto) {
   var f = function() {};
   f.prototype = proto;
   return new f();
  };
  
  var Constructor = function() {};
  Constructor.prototype = sharedPrototype;
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Object.create()
var i = 100;
var o, a = [];
while (i--) a.push(Object.create(sharedPrototype));

while (a.length) {
  o = a.shift();
  while (i < 100) {
    o.one();
    o.two();
    o.three();
  }
}
ready
Crockford Create
var i = 100;
var o, a = [];
while (i--) a.push(crockfordCreate(sharedPrototype));

while (a.length) {
  o = a.shift();
  while (i < 100) {
    o.one();
    o.two();
    o.three();
  }
}
ready
Constructor
var i = 100;
var o, a = [];
while (i--) a.push(new Constructor);


while (a.length) {
  o = a.shift();
  while (i < 100) {
    o.one();
    o.two();
    o.three();
  }
}
ready

Revisions

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