Object.create vs Crockford vs Constructor

JavaScript performance comparison

Revision 24 of this test case created

Preparation code

<script>
  var sharedPrototype = {
   one: function() {
    return 1;
   },
   two: function() {
    return 2;
   },
   three: function() {
    return 3;
   }
  };
 
  var ObjectCheckCreate = function(proto) {
    for(var o in proto){
      if(o == 'check')
        continue;
    }
    Object.create(sharedPrototype);
  };
 
  var extend = function(prototype){
    var obj = {};
    for(var c in prototype)
      obj[c] = prototype[c];
    return obj;
  }
 
  var Constructor = function() {};
  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() with property checking
var i = 100;
while (i--) ObjectCheckCreate(sharedPrototype);
//while (i--) Object.create(sharedPrototype);
pending…
Object Extend
var i = 100;
while (i--) extend(sharedPrototype);
pending…
Constructor
var i = 100;
while (i--) new Constructor;
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