Object.create vs Crockford vs Constructor (v56)

Revision 56 of this benchmark created on


Preparation HTML

<script>
  var sharedPrototype = {
   one: function() {
    return 1;
   },
   two: function() {
    return 2;
   },
   three: function() {
    return 3;
   }
  };
  
  var rodrigoCreate = function () {
      return new Constructor;
  };
  
  var crockfordCreate = function(proto) {
   var f = function() {};
   f.prototype = proto;
   return new f();
  }; 
 
  function protoCreate(proto) {
   return {__proto__: proto};
  };
  
  var Constructor = function() {};
  Constructor.prototype = sharedPrototype;
  
  var cornfordCreate = (function() {
   var f = function() {};
   return function(proto) {
    f.prototype = proto;
    return new f();
   };
  })();
  var TemplateClass = function () {};
  function temp(object) {
      TemplateClass.prototype = object;
      var result = new TemplateClass();
      TemplateClass.prototype = null;
      return result;
  }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Object.create()
Object.create(sharedPrototype);
ready
Crockford Create
crockfordCreate(sharedPrototype);
ready
temp
temp(sharedPrototype);
ready
Cornford Create
cornfordCreate(sharedPrototype);
ready
protoCreate
protoCreate(sharedPrototype);
ready

Revisions

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