Prototype vs instance functions (v5)

Revision 5 of this benchmark created on


Test runner

Ready to run.

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

myClass.prototype.method = function(x,y){
    return x + y;
};
var instance = new myClass();
for(var i = 0; i < 1000; i++){
    instance.method(i, 5);
};
ready
Instance V2
var myClass = (function(){
    var myClassConstructor = function myClass(){
       function method(x, y){
           return x + y;
       };
       return { method : method };
    }
    return myClassConstructor;
})();

var instance = new myClass();
for(var i = 0; i < 1000; i++){
    instance.method(i, 5);
};
ready
Instance V3
var myClass = (function(){
    function myClassConstructor(){
       function method(x, y){
           return x + y;
       };
       return { method : method };
    }
    return myClassConstructor;
})();

var instance = new myClass();
for(var i = 0; i < 1000; i++){
    instance.method(i, 5);
};
ready

Revisions

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