Object.create() vs. constructor vs. object literal (v88)

Revision 88 of this benchmark created on


Preparation HTML

<script>
var myPrototype = {
    methodA: function () {},
    methodB: function () {},
    methodC: function () {}
  };
  Obj = function() {
   this.p = 1;
  }
  
//superclass method
Obj.prototype.methodA= function () {};
Obj.prototype.methodB= function () {};
Obj.prototype.methodC= function () {};

  propObj = {
   p: {
    value: 1
   }
  };
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Object.create() using in-place property object
o = Object.create(myPrototype);
ready
Object.create() using pre-defined property object
o = Object.create(Object.prototype, propObj);
ready
Constructor function
o = new Obj();
 
ready
Object literal
o = {
 p: 1,
methodA:myPrototype.methodA,
methodA:myPrototype.methodB,
methodA:myPrototype.methodC

};
ready

Revisions

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