Prototype vs Module pattern performance

Benchmark created by WTK 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() {
    var foo = function() {
        alert('foo');
    }, bar = function() {
        alert('bar');
    };

    return {foo: foo, bar: 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.