New Obj vs Obj Literal (v2)

Revision 2 of this benchmark created on


Description

Testing performance of a ton of objects created using object literal vs new.

Test runner

Ready to run.

Testing in
TestOps/sec
Object Literal
var arr = [];
for (var i = 0; i < 10000; i++) {
  arr.push({
    name: "test",
    bark: function() {
      alert("woof");
    }
  })
}
ready
Methods Defined via prototype
var arr = [];

function Dog(name) {
  this.name = name;
}

Dog.prototype.bark = function() {
  alert("bark");
}

for (var i = 0; i < 10000; i++) {
  arr.push(new Dog("fido"));
}
ready
New Object (with Method)
var arr = [];

function Dog() {
  this.name = "test";

  function bark() {
    alert("woof");
  };
  this.bark = bark;
}
for (var i = 0; i < 10000; i++) {
  arr.push(new Dog());
}
ready

Revisions

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