Prototype vs Instance vs Literal vs Function vs Module/IIFE functions (v11)

Revision 11 of this benchmark created by Gregg Stelmach on


Test runner

Ready to run.

Testing in
TestOps/sec
Instance
var myClass = function(){
    this.method = function(x, y){
        return x + y;
    }
};
for(var i = 0; i < 15; i++){
    var instance = new myClass();
    instance.method();
};
ready
Prototype
var myClass = function(){
};

myClass.prototype.method = function(x,y){
    return x + y;
};
for(var i = 0; i < 15; i++){
    var instance = new myClass();
    instance.method();
};
ready
Obj Literal
var myClass = { method: function method(x, y){return x + y;},}

for(var i = 0; i < 15; i++){
    myClass.method();
};
ready
Stand Alone Method
function method(x, y) {
    return x + y;
}

for(var i = 0; i < 15; i++){
    method();
};
ready
Module IIFE
var myClass = (function() {
    function method(x, y) {
        return x + y;
    }
    return {
        method: method
    };
})();

for(var i = 0; i < 15; i++){
    myClass.method()
}
ready

Revisions

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