Standard prototype vs module pattern

Benchmark created by ElliotB on


Setup

var dummyclass = (function() {
    
        var _privateMethod1 = function() {
                var i = 10000;
                var a = [];
                while(i--) {
                        a.push("hello world");
                }
        
                return a;
        
        }
        
        var _privateMethod2 = function() {
                var i = 10000;
                var a = [];
                while(i--) {
                        a.push("hello world");
                }
        
                return a;
        }
        
        var _privateMethod3 = function() {
                var i = 10000;
                var a = [];
                while(i--) {
                        a.push("hello world");
                }
        
                return a;
        }
        
        var _privateMethod4 = function() {
                var i = 10000;
                var a = [];
                while(i--) {
                        a.push("hello world");
                }
        
                return a;
        }
        
        var _privateMethod5 = function() {
                var i = 10000;
                var a = [];
                while(i--) {
                        a.push("hello world");
                }
        
                return a;
        }
    
        var constructor = function(iUserId) {
                this.iUserId = iUserId;
        }
        
        constructor.prototype.public_method1 = function() {
        
                var i = 10000;
                var a = [];
                while(i--) {
                        a.push("hello world");
                }
        
                return a;
        }
        
        constructor.prototype.public_method_test = function() {
                var i = 10;
                while(i--) {
                        _privateMethod5.call(this);
                }
        }
    
      return constructor;
    
    })();
    
    var dummyclassb = function(iUserId) {
        this.iUserId = iUserId;
    
    
    }
    
    dummyclassb.prototype._privateMethod1 = function() {
        var i = 10000;
        var a = [];
        while(i--) {
                a.push("hello world");
        }
    
        return a;
    }
    
    dummyclassb.prototype._privateMethod2 = function() {
        var i = 10000;
        var a = [];
        while(i--) {
                a.push("hello world");
        }
    
        return a;
    }
    
    dummyclassb.prototype._privateMethod3 = function() {
        var i = 10000;
        var a = [];
        while(i--) {
                a.push("hello world");
        }
    
        return a;
    }
    
    dummyclassb.prototype._privateMethod4 = function() {
        var i = 10000;
        var a = [];
        while(i--) {
                a.push("hello world");
        }
    
        return a;
    }
    
    dummyclassb.prototype._privateMethod5 = function() {
        var i = 10000;
        var a = [];
        while(i--) {
                a.push("hello world");
        }
    
        return a;
    }
    
    dummyclassb.prototype.public_method1 = function() {
        
                var i = 10000;
                var a = [];
                while(i--) {
                        a.push("hello world");
                }
        
                return a;
        }
        
    dummyclassb.prototype.public_method_test = function() {
        var i = 10;
        while(i--) {
                this._privateMethod5();
        }
    }
    
    var oDummyA = new dummyclass(5);
    var oDummyB = new dummyclassb(5);

Test runner

Ready to run.

Testing in
TestOps/sec
Initialize: standard prototype
var oDummy = new dummyclassb(5);
ready
Initialize: module pattern
var oDummy = new dummyclass(5);
ready
Execution: standard prototype
var a = 10;
while (a--) {
    oDummyB.public_method_test();
}
ready
Execution: module pattern
var a = 10;
while (a--) {
    oDummyA.public_method_test();
}
ready

Revisions

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

  • Revision 1: published by ElliotB on