Inheritance performance - method calls (v7)

Revision 7 of this benchmark created by kogarashisan1 on


Description

Accurate tests of JavaScript class inheritance models.

These tests aim to provide adequate and accurate results by modelind real-life application behaviour and avoiding common pitfalls. For source code and detailed explanation - please visit the repository:

https://github.com/kogarashisan/PerfTests

Tested libraries does not include Prototype or MooTools, cause they are slow. Ext.JS is not included, cause it affects results of other tests.

*** IF CURRENT PAGE IS BROKEN - then visit repository for the link to proper version. ***

Preparation HTML

<script src="http://kogarashisan.github.io/PerfTests/export/dependencies-v2.js"></script>
<script src="http://kogarashisan.github.io/PerfTests/export/bundle-v2.js"></script>

<script>

/*
Each model exports two children into window, for example:
        TypeScriptChildA and TypeScriptChildB

This code creates 5 instances of each child for each model
and stores them in global model_instances array.

Model test then can be done as follows:

var instances = model_instances[0]; // TypeScript
// just a large loop
for (var i = 0; i < 100000; i++) {
        // call `method` on each of 10 different instances
        for (var c = 0; c < 10; c++) {
                instances[c].method();
        }
}
*/

var model_names = [
        /* 0  */'TypeScript',
        /* 1  */'CMBrowserMono', // ClassManager
        /* 2  */'CMBrowserPoly', // ClassManager
        /* 3  */'CMServerFullrefMono', // ClassManager
        /* 4  */'CMServerPartialrefMono', // ClassManager
        /* 5  */'CMServerPartialrefPoly', // ClassManager
        /* 6  */'DNW_IW_', // DotNetWise inheritWith
        /* 7  */'DNW_FC_', // DotNetWise fastClass
        /* 8  */'Fiber',
        /* 9  */'JR', // John Resig
        /* 10 */'NativeUnwrapped',
        /* 11 */'NativeWrapped',
        /* 12 */'Klass', // klass
        /* 13 */'AugmentClassical' // augment
];

var model_instances = [];

for (var model_index = 0; model_index < model_names.length; model_index++) {
        var constructorA = window[model_names[model_index] + 'ChildA'];
        var constructorB = window[model_names[model_index] + 'ChildB'];
        model_instances[model_index] = [
                new constructorA("a1"),
                new constructorB("b1"),
                new constructorA("a2"),
                new constructorB("b2"),
                new constructorA("a3"),
                new constructorB("b3"),
                new constructorA("a4"),
                new constructorB("b4"),
                new constructorA("a5"),
                new constructorB("b5")
        ];

        // warm-up loop
        for (var dummy = 0; dummy < 5; dummy++) {
                for (var c = 0; c < 10; c++) {
                        model_instances[model_index][c].method();
                }
        }
}
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
TypeScript
var instances = model_instances[0]; // TypeScriptChildX
for (var i = 0; i < 50000; i++) {
    for (var c = 0; c < 10; c++) {
        instances[c].method();
    }
}
ready
ClassManager / Browser / Monomorphic
var instances = model_instances[1]; // CMBrowserMonoChildX
for (var i = 0; i < 50000; i++) {
    for (var c = 0; c < 10; c++) {
        instances[c].method();
    }
}
ready
ClassManager / Browser / Polymorphic
var instances = model_instances[2]; // CMBrowserPolyChildX
for (var i = 0; i < 50000; i++) {
    for (var c = 0; c < 10; c++) {
        instances[c].method();
    }
}
ready
ClassManager / Server / Monomorphic / Full
var instances = model_instances[3]; // CMServerFullrefMonoChildX
for (var i = 0; i < 50000; i++) {
    for (var c = 0; c < 10; c++) {
        instances[c].method();
    }
}
ready
ClassManager / Server / Monomorphic / Partial
var instances = model_instances[4]; // CMServerPartialrefMonoChildX
for (var i = 0; i < 50000; i++) {
    for (var c = 0; c < 10; c++) {
        instances[c].method();
    }
}
ready
ClassManager / Server / Polymorphic / Partial
var instances = model_instances[5]; // CMServerPartialrefPolyChildX
for (var i = 0; i < 50000; i++) {
    for (var c = 0; c < 10; c++) {
        instances[c].method();
    }
}
ready
DotNetWise inheritWith
var instances = model_instances[6]; // DNW_IW_ChildX
for (var i = 0; i < 50000; i++) {
    for (var c = 0; c < 10; c++) {
        instances[c].method();
    }
}
ready
DotNetWise fastClass
var instances = model_instances[7]; // DNW_FC_ChildX
for (var i = 0; i < 50000; i++) {
    for (var c = 0; c < 10; c++) {
        instances[c].method();
    }
}
ready
Fiber
var instances = model_instances[8]; // FiberChildX
for (var i = 0; i < 50000; i++) {
    for (var c = 0; c < 10; c++) {
        instances[c].method();
    }
}
ready
John Resig
var instances = model_instances[9]; // JRChildX
for (var i = 0; i < 50000; i++) {
    for (var c = 0; c < 10; c++) {
        instances[c].method();
    }
}
ready
Native (unwrapped)
var instances = model_instances[10]; // NativeUnwrappedChildX
for (var i = 0; i < 50000; i++) {
    for (var c = 0; c < 10; c++) {
        instances[c].method();
    }
}
ready
Native (wrapped)
var instances = model_instances[11]; // NativeWrappedChildX
for (var i = 0; i < 50000; i++) {
    for (var c = 0; c < 10; c++) {
        instances[c].method();
    }
}
ready
klass
var instances = model_instances[12]; // KlassChildX
for (var i = 0; i < 50000; i++) {
    for (var c = 0; c < 10; c++) {
        instances[c].method();
    }
}
ready
augment
var instances = model_instances[13]; // AugmentClassicalChildX
for (var i = 0; i < 50000; i++) {
    for (var c = 0; c < 10; c++) {
        instances[c].method();
    }
}
ready

Revisions

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

  • Revision 2: published by kogarashisan1 on
  • Revision 3: published by kogarashisan1 on
  • Revision 4: published by Billy Tetrud on
  • Revision 5: published by Billy Tetrud on
  • Revision 6: published by Billy Tetrud on
  • Revision 7: published by kogarashisan1 on
  • Revision 9: published by Aadit M Shah on
  • Revision 10: published by kogarashisan1 on
  • Revision 11: published by Enzo on
  • Revision 12: published by kogarashisan1 on