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

Revision 40 of this benchmark created by ju1ius on


Preparation HTML

<script>
  Obj = function() {
   this.p = 1;
   this.foo = "foo";
   var bar = "bar";
   this.getBar = function(){ return bar; }
  };
  Obj.prototype.getFoo = function(){ return this.foo; };

  propObj = {
   p: {value: 1},
   foo: {value: "foo"},
   bar: {value: "bar"},
   getFoo: {value: function(){ return this.foo; }},
   getBar: {value: function(){ return this.bar; }}
  };
</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
Simple version
o = {
   p: 1,
   foo: "foo",
   bar: "bar",
   getFoo: function(){ return this.foo; },
   getBar: function(){ return this.bar; }
};
ready

Revisions

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