Prototype vs Module pattern performance (v7)

Revision 7 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');
}
Klass.prototype.foo1 = function() {
    alert('foo');
}
Klass.prototype.bar1 = function() {
    alert('bar');
}

Klass.prototype.foo2 = function() {
    alert('foo');
}
Klass.prototype.bar2 = function() {
    alert('bar');
}

Klass.prototype.foo3 = function() {
    alert('foo');
}
Klass.prototype.bar3 = function() {
    alert('bar');
}
Klass.prototype.foo4 = function() {
    alert('foo');
}
Klass.prototype.bar4 = function() {
    alert('bar');
}



var i = 20, objs = [];
while(i--) {
    objs.push(new Klass());
}
ready
Module pattern
Klass = function() {
    var foo = function() {
        alert('foo');
    }, bar = function() {
        alert('bar');
    },foo1 = function() {
        alert('foo');
    }, bar1 = function() {
        alert('bar');
    },foo2 = function() {
        alert('foo');
    }, bar2 = function() {
        alert('bar');
    },foo3 = function() {
        alert('foo');
    }, bar3 = function() {
        alert('bar');
    },foo4 = function() {
        alert('foo');
    }, bar4 = function() {
        alert('bar');
    };

    return {
foo: foo, bar: bar,foo1: foo1, bar1: bar1,foo2: foo2, bar2: bar2,foo3: foo3, bar3: bar3,foo4: foo4, bar4: bar4}
}

var i = 20, 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.