Prototype vs Module pattern performance (v3)

Revision 3 of this benchmark created on


Test runner

Ready to run.

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

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

    this.bar = function() {
        alert('bar');
    };
}

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

Revisions

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