Private Property Testing (v3)

Revision 3 of this benchmark created by Rich Kosiba on


Setup

var test1 = function() {
        var private = {};
    
        var test1 = function() {
                private.first = 1;
                private.second = 2;
                private.third = 3;
        };
    
        test1.prototype.first = function(val) {
                if(typeof val === 'number') {
                        private.first = val;
                }
                console.debug(private.first);
        };
    
        test1.prototype.second = function(val) {
                if(typeof val === 'number') {
                        private.second = val;
                }
                console.debug(private.second);
        };
    
        test1.prototype.third = function(val) {
                if(typeof val === 'number') {
                        private.third = val;
                }
                console.debug(private.third);
        };
    
        return new test1();
    };
    
    var test2 = function() {
        this.first = 1;
        this.second = 2;
        this.third = 3;
    };
    
    test2.prototype.first = function(val) {
        if(typeof val === 'number') {
                this.first = val;
        }
        console.debug(this.first);
    };
    
    test2.prototype.second = function(val) {
        if(typeof val === 'number') {
                this.second = val;
        }
        console.debug(this.second);
    };
    
    test2.prototype.third = function(val) {
        if(typeof val === 'number') {
                this.third = val;
        }
        console.debug(this.third);
    };

Test runner

Ready to run.

Testing in
TestOps/sec
With Private Properties
var test = test1();
test.first();
test.second();
test.third();
test.second(42);
test.second();
ready
Without Private Properties
var test = new test2();
test.first();
test.second();
test.third();
test.second(42);
test.second();
ready

Revisions

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

  • Revision 1: published by Rich Kosiba on
  • Revision 2: published by Rich Kosiba on
  • Revision 3: published by Rich Kosiba on
  • Revision 4: published by Rich Kosiba on
  • Revision 5: published by Rich Kosiba on