Object.create() vs. constructor

JavaScript performance comparison

Revision 112 of this test case created

Preparation code

<script>
var test = null;

var Obj = function() {
  this.n = 1;
  this.b = false;
  this.o = null;
};

Obj.prototype = {
        method1: function(){},
        method2: function(){},
        method3: function(){},
        method4: function(){},
        method5: function(){},
        method6: function(){},
        method7: function(){},
        method8: function(){},
        method9: function(){},
        method10: function(){},
        method11: function(){},
        method12: function(){},
        method13: function(){},
        method14: function(){},
        method15: function(){},
        method16: function(){},
        method17: function(){},
        method18: function(){},
        method19: function(){},
        method20: function(){}
};
 
var protoObj = {
  n: 1,
  b: false,
  o: null
};
</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() using pre-defined prototype object
test = Object.create(protoObj);
pending…
Constructor function
test = new Obj();
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