Inheritance performance - method calls (v4)

Revision 4 of this benchmark created by Billy Tetrud on


Description

Accurate tests of the fastest JavaScript class inheritance models. This test tests method calls.

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 do 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);
        }
});


var TypeScriptinstanceA = new TypeScriptChildA("a");
var TypeScriptinstanceB = new TypeScriptChildB("b");

var CMBrowserMonoChildinstanceA = new CMBrowserMonoChildA("a");
var CMBrowserMonoChildinstanceB = new CMBrowserMonoChildB("b");

var CMBrowserPolyChildinstanceA = new CMBrowserPolyChildA("a");
var CMBrowserPolyChildinstanceB = new CMBrowserPolyChildB("b");

var CMServerFullrefMonoChildinstanceA = new CMServerFullrefMonoChildA("a");
var CMServerFullrefMonoChildinstanceB = new CMServerFullrefMonoChildB("b");

var CMServerPartialrefMonoChildinstanceA = new CMServerPartialrefMonoChildA("a");
var CMServerPartialrefMonoChildinstanceB = new CMServerPartialrefMonoChildB("b");

var CMServerPartialrefPolyChildinstanceA = new CMServerPartialrefPolyChildA("a");
var CMServerPartialrefPolyChildinstanceB = new CMServerPartialrefPolyChildB("b");

var DNW_IW_ChildinstanceA = new DNW_IW_ChildA("a");
var DNW_IW_ChildinstanceB = new DNW_IW_ChildB("b");

var DNW_FC_ChildinstanceA = new DNW_FC_ChildA("a");
var DNW_FC_ChildinstanceB = new DNW_FC_ChildB("b");

var FiberinstanceA = new FiberChildA("a");
var FiberinstanceB = new FiberChildB("b");

var JohnResiginstanceA = new JRChildA("a");
var JohnResiginstanceB = new JRChildB("b");

var NativeinstanceA = new NativeChildA("a");
var NativeinstanceB = new NativeChildB("b");

var ProtoinstanceA = ProtoChildA("a");
var ProtoinstanceB = ProtoChildB("b");
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
TypeScript
for (var i = 0; i < 100000; i++) {
    TypeScriptinstanceA.method();
    TypeScriptinstanceB.method();
}
ready
Lava ClassManager / Browser / Monomorphic
for (var i = 0; i < 100000; i++) {
    CMBrowserMonoChildinstanceA.method();
    CMBrowserMonoChildinstanceB.method();
}
ready
Lava ClassManager / Browser / Polymorphic
for (var i = 0; i < 100000; i++) {
    CMBrowserPolyChildinstanceA.method();
    CMBrowserPolyChildinstanceB.method();
}
ready
Lava ClassManager / Server / Monomorphic / Full
for (var i = 0; i < 100000; i++) {
    CMServerFullrefMonoChildinstanceA.method();
    CMServerFullrefMonoChildinstanceB.method();
}
ready
Lava ClassManager / Server / Monomorphic / Partial
for (var i = 0; i < 100000; i++) {
    CMServerPartialrefMonoChildinstanceA.method();
    CMServerPartialrefMonoChildinstanceB.method();
}
ready
Lava ClassManager / Server / Polymorphic / Partial
for (var i = 0; i < 100000; i++) {
    CMServerPartialrefPolyChildinstanceA.method();
    CMServerPartialrefPolyChildinstanceB.method();
}
ready
DotNetWise inheritWith
for (var i = 0; i < 100000; i++) {
    DNW_IW_ChildinstanceA.method();
    DNW_IW_ChildinstanceB.method();
}
ready
DotNetWise fastClass
for (var i = 0; i < 100000; i++) {
    DNW_FC_ChildinstanceA.method();
    DNW_FC_ChildinstanceB.method();
}
ready
Fiber
for (var i = 0; i < 100000; i++) {
    FiberinstanceA.method();
    FiberinstanceB.method();
}
ready
John Resig's Class
for (var i = 0; i < 100000; i++) {
    JohnResiginstanceA.method();
    JohnResiginstanceB.method();
}
ready
Native
for (var i = 0; i < 100000; i++) {
    NativeinstanceA.method();
    NativeinstanceB.method();
}
ready
Proto
for (var i = 0; i < 100000; i++) {
    ProtoinstanceA.method();
    ProtoinstanceB.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