Object.create vs Crockford vs Constructor (v11)

Revision 11 of this benchmark created 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(x) {
   this.x = x
  };
  Constructor.prototype = sharedPrototype;
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Object.create()
var i = 100;
while (i--) {
 var o = Object.create(sharedPrototype);
 o.x = 10;
}
ready
Crockford Create
var i = 100;
while (i--) {
 var o = crockfordCreate(sharedPrototype);
 o.x = 10;
}
ready
Constructor
var i = 100;
while (i--) {
 var o = new Constructor(10)
};
ready

Revisions

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