Object.create vs Crockford vs Constructor

JavaScript performance comparison

Revision 53 of this test case created by Alex Shvets

Preparation code

<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();
   };
  })();
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Object.create()
var i = 100;
while (i--) Object.create(sharedPrototype);
pending…
Crockford Create
var i = 100;
while (i--) crockfordCreate(sharedPrototype);
pending…
Proto
var i = 100;
while (i--) ({__proto__: sharedPrototype});
pending…
Cornford Create
var i = 100;
while (i--) cornfordCreate(sharedPrototype);
pending…
protoCreate
var i = 100;
while (i--) protoCreate(sharedPrototype);
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment