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

Revision 54 of this benchmark created by Andrew F on


Preparation HTML

<script>
  var o;

  var Obj = function() {
   this.p = 1;
  };
  
  var propObj = {
   p: {
    value: 1
   }
  };
  
  var protoObj = {p: 1};
  
  function object(o) {
      function F() {}
      F.prototype = o;
      return new F();
  }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Object.create() using in-place property object
o = Object.create(Object.prototype, {
 p: {
  value: 1
 }
});
ready
Object.create() using pre-defined property object
o = Object.create(Object.prototype, propObj);
ready
Constructor function
o = new Obj();
ready
Object.create() using in-place prototype object
o = Object.create({p: 1});
ready
Object.create() using pre-defined prototype object
o = Object.create(protoObj);
ready
Crockford method using in-place prototype object
o = object({p: 1});
ready
Crockford method using pre-defined prototype object
o = object(protoObj);
ready
Object literal
o = {p: 1};
ready
last
o = {'p':1};
ready

Revisions

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