Prototype vs Module vs Closure performance (v17)

Revision 17 of this benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
Prototypal
Klass = function(s) {
  this.s = s;
}
Klass.prototype.foo = function() {
  alert(this.s);
}
Klass.prototype.bar = function() {
  alert(this.s);
}

var i = 1000,
    objs = [];
while (i--) {
  objs.push(new Klass(1));
}
ready
Module pattern
Klass = function(s) {
  var foo = function() {
      alert(s);
      },
      bar = function() {
      alert(s);
      };

  return {
    foo: foo,
    bar: bar
  }
}

var i = 1000,
    objs = [];
while (i--) {
  objs.push(new Klass(1));
}
ready
Closure
Klass = function(s) {
  this.foo = function() {
    alert(s);
  }
  this.bar = function() {
    alert(s);
  }
}


var i = 1000,
    objs = [];
while (i--) {
  objs.push(new Klass(1));
}
ready

Revisions

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