Inheritance performance - object construction (v2)

Revision 2 of this benchmark created by Billy Tetrud on


Description

Accurate tests of the fastest JavaScript class inheritance models. This test tests instance creation.

These tests aim to provide adequate and accurate results by modeling real-life application behavior and avoiding common performance-testing pitfalls. For source code and detailed explanation of the techniques used to create accurate tests - please visit https://github.com/kogarashisan/PerfTests.

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

Related test:

Preparation HTML

<script src="http://kogarashisan.github.io/PerfTests/export/dependencies-v1.js"></script>
<script src="http://kogarashisan.github.io/PerfTests/export/bundle-v1.js"></script>
<script src="http://www.btetrud.com/files/proto.umd.js"></script>

<script>
var ProtoParent = proto(function() {var cache_buster_0502;

        this.init = function(instance_string) {var cache_buster_0503;
                this.counter = 0;
                this.instance_array = [];
                this.instance_string = instance_string;
        };

        this.method = function (prevent_inline) {var cache_buster_0504;
                if (this.counter > 99)
                        this.counter = this.counter / 2;
                else
                        this.counter++;
                if (prevent_inline) {
                        var i = 0;
                        for (i = 0; i < 1; i++) dummy.method();
                        for (i = 0; i < 1; i++) dummy.method();
                        for (i = 0; i < 1; i++) dummy.method();
                        for (i = 0; i < 1; i++) dummy.method();
                        for (i = 0; i < 1; i++) dummy.method();
                        for (i = 0; i < 1; i++) dummy.method();
                        for (i = 0; i < 1; i++) dummy.method();
                        for (i = 0; i < 1; i++) dummy.method();
                        for (i = 0; i < 1; i++) dummy.method();
                        for (i = 0; i < 1; i++) dummy.method();
                }
        }
});

var ProtoChildA = proto(ProtoParent, function(superclass) {var cache_buster_0505;

        this.init = function(instance_string) {var cache_buster_0506;
                this.member_a = 1;
                superclass.init.call(this, instance_string);
        };

        this.method = function() {var cache_buster_0507;
                this.member_a = -this.member_a;
                superclass.method.call(this, false);
        }
});

var ProtoChildB = proto(ProtoParent, function(superclass) {var cache_buster_0508;

        this.init = function(instance_string) {var cache_buster_0509;
                this.member_b = -1;
                superclass.init.call(this, instance_string);
        };

        this.method = function() {var cache_buster_0510;
                this.member_b = -this.member_b;
                superclass.method.call(this, false);
        }
});
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
TypeScript
for (var i = 0; i < 20000; i++) {
    new TypeScriptChildA("a");
    new TypeScriptChildB("b");
}
ready
Lava ClassManager / Browser / Monomorphic
for (var i = 0; i < 20000; i++) {
    new CMBrowserMonoChildA("a");
    new CMBrowserMonoChildB("b");
}
ready
Lava ClassManager / Browser / Polymorphic
for (var i = 0; i < 20000; i++) {
    new CMBrowserPolyChildA("a");
    new CMBrowserPolyChildB("b");
}
ready
Lava ClassManager / Server / Monomorphic / Full
for (var i = 0; i < 20000; i++) {
    new CMServerFullrefMonoChildA("a");
    new CMServerFullrefMonoChildB("b");
}
ready
Lava ClassManager / Server / Monomorphic / Partial
for (var i = 0; i < 20000; i++) {
    new CMServerPartialrefMonoChildA("a");
    new CMServerPartialrefMonoChildB("b");
}
ready
Lava ClassManager / Server / Polymorphic / Partial
for (var i = 0; i < 20000; i++) {
    new CMServerPartialrefPolyChildA("a");
    new CMServerPartialrefPolyChildB("b");
}
ready
DotNetWise inheritWith
for (var i = 0; i < 20000; i++) {
    new DNW_IW_ChildA("a");
    new DNW_IW_ChildB("b");
}
ready
DotNetWise fastClass
for (var i = 0; i < 20000; i++) {
    new DNW_FC_ChildA("a");
    new DNW_FC_ChildB("b");
}
ready
Fiber
for (var i = 0; i < 20000; i++) {
    new FiberChildA("a");
    new FiberChildB("b");
}
ready
John Resig's Class
for (var i = 0; i < 20000; i++) {
    new JRChildA("a");
    new JRChildB("b");
}
ready
Native
for (var i = 0; i < 20000; i++) {
    new NativeChildA("a");
    new NativeChildB("b");
}
ready
Proto
for (var i = 0; i < 20000; i++) {
    ProtoChildA("a");
    ProtoChildB("b");
}
ready

Revisions

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

  • Revision 1: published by kogarashisan1 on
  • Revision 2: published by Billy Tetrud on