Object.create vs Crockford vs Constructor

JavaScript performance comparison

Revision 11 of this test case created

Preparation code

<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

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--) {
 var o = Object.create(sharedPrototype);
 o.x = 10;
}
pending…
Crockford Create
var i = 100;
while (i--) {
 var o = crockfordCreate(sharedPrototype);
 o.x = 10;
}
pending…
Constructor
var i = 100;
while (i--) {
 var o = new Constructor(10)
};
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