Prototype Chaining Benchmark

Benchmark created on


Description

To see how much performance loss happens from prototype chaining

Setup

var lib = {};
    
    lib.base = function () { };
    lib.base.prototype.foo = function ()
    {
    }
    
    lib.base.prototype.bar = function ()
    {
    }
    
    lib.Test1 = function () { };
    lib.Test1.prototype = new lib.base();
    lib.Test1.constructor = lib.Test1;
    lib.Test1.prototype.foo = function ()
    {
        this.bar();
    }
    
    lib.Test2 = function () { };
    lib.Test2.prototype = new lib.Test1();
    lib.Test2.constructor = lib.Test2;
    lib.Test2.prototype.foo = function ()
    {
        this.bar();
    }
    
    lib.Test3 = function () { };
    lib.Test3.prototype = new lib.Test2();
    lib.Test3.constructor = lib.Test3;
    lib.Test3.prototype.foo = function ()
    {
        this.bar();
    }
    
    lib.Test4 = function () { };
    lib.Test4.prototype = new lib.Test3();
    lib.Test4.constructor = lib.Test4;
    lib.Test4.prototype.foo = function ()
    {
        this.bar();
    }
    
    lib.Test5 = function () { };
    lib.Test5.prototype = new lib.Test4();
    lib.Test5.constructor = lib.Test5;
    lib.Test5.prototype.foo = function ()
    {
        this.bar();
    }
    
    lib.Test6 = function () { };
    lib.Test6.prototype = new lib.Test5();
    lib.Test6.constructor = lib.Test6;
    lib.Test6.prototype.foo = function ()
    {
        this.bar();
    }
    
    lib.Test7 = function () { };
    lib.Test7.prototype = new lib.Test6();
    lib.Test7.constructor = lib.Test7;
    lib.Test7.prototype.foo = function ()
    {
        this.bar();
    }
    
    lib.Test8 = function () { };
    lib.Test8.prototype = new lib.Test7();
    lib.Test8.constructor = lib.Test8;
    lib.Test8.prototype.foo = function ()
    {
        this.bar();
    }
    
    lib.vars = {};
    
    lib.vars.base = new lib.base();
    lib.vars.Test1 = new lib.Test1();
    lib.vars.Test2 = new lib.Test2();
    lib.vars.Test3 = new lib.Test3();
    lib.vars.Test4 = new lib.Test4();
    lib.vars.Test5 = new lib.Test5();
    lib.vars.Test6 = new lib.Test6();
    lib.vars.Test7 = new lib.Test7();
    lib.vars.Test8 = new lib.Test8();

Test runner

Ready to run.

Testing in
TestOps/sec
Base
lib.vars.base.foo();
ready
1 Chain
lib.vars.Test1.foo();
ready
2 Chains
lib.vars.Test2.foo();
ready
3 Chains
lib.vars.Test3.foo();
ready
4 Chains
lib.vars.Test4.foo();
ready
5 Chains
lib.vars.Test5.foo();
ready
6 Chains
lib.vars.Test6.foo();
ready
7 Chains
lib.vars.Test7.foo();
ready
8 Chains
lib.vars.Test8.foo();
ready

Revisions

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