Prototype vs. this_100 methods per object (v43)

Revision 43 of this benchmark created on


Setup

function T1() {}
    
    for (var i = 0; i < 100; i++)
        T1.prototype["myMethod_" + i] = function() {};
    
    function T2() {
        for (var i = 0; i < 100; i++)
            this["myMethod_" + i] = function() {};
    }
    
    function T3() {
        for (var i = 0; i < 100; i++)
            this["test_" + i] = [false, 0, "0"];
    }
    
    function T4() {
        for (var i = 0; i < 30; i++)
            this["myMethod_" + i] = function() {
                for (var i = 0; i < 30; i++)
                    this.a = [false, 0, "0", function() {}];
            };
    }
    function T5() {
        for (var i = 0; i < 30; i++)
            this["myMethod_" + i] = function() {
                for (var i = 0; i < 30; i++)
                    this.a = [false, 0, "0", function() {}];
            };
            for (var i = 0; i < 100; i++)
                this["test_" + i] = [false, 0, "0"];
    }

Test runner

Ready to run.

Testing in
TestOps/sec
Using prototype
new T1;
ready
Using this
new T2;
ready
Test 3
new T3;
ready
Test 4
new T4;
ready
Test 5
new T5;
ready

Revisions

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