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

Revision 89 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 () {};

function factory( func ) {
  var obj = {};
  var args = [];
  for (var i=1, l=arguments.length; i<l; i++) args[i-1] = arguments[i];
  func.apply( obj, args );
  obj.constructor = func;
  return obj;
}

  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 = factory(Obj);
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.