Prototype vs Module vs Closure performance

JavaScript performance comparison

Revision 17 of this test case created

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/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));
}
pending…
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));
}
pending…
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));
}
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment