Prototype vs instance functions (v8)

Revision 8 of this benchmark created on


Test runner

Ready to run.

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

myClass.prototype.method = function(x, y) {
  return x + y;
};
var instance = new myClass();
for (var i = 0; i < 1000; i++) {
  instance.method(i, i + 1);
};
ready
Prototype (directly)
var myClass = function() {};

myClass.prototype.method = function(x, y) {
  return x + y;
};
for (var i = 0; i < 1000; i++) {
  myClass.prototype.method(i, i + 1);
};
ready

Revisions

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