Prototype vs instance functions (v15)

Revision 15 of this benchmark created by Art on


Description

checking if creation of instances via factory slows it down

Test runner

Ready to run.

Testing in
TestOps/sec
Instance
var myClass = function() {
  this.method = function(x, y) {
    return x + y;
  }
};
for (var i = 0; i < 1000; i++) {
  var instance = new myClass();
  instance.method();
};
ready
Prototype
var myClass = function() {};

myClass.prototype.method = function(x, y) {
  return x + y;
};

function factory() {
  return new myClass();
}
for (var i = 0; i < 1000; i++) {
  var instance = factory();
  instance.method();
};
ready

Revisions

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