Inheritance performance - method calls, incl proto (v3)

Revision 3 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.

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>
!function(r,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):"object"==typeof exports?exports.proto=e():r.proto=e()}(this,function(){return function(r){function e(t){if(n[t])return n[t].exports;var o=n[t]={exports:{},id:t,loaded:!1};return r[t].call(o.exports,o,o.exports,e),o.loaded=!0,o.exports}var n={};return e.m=r,e.c=n,e.p="",e(0)}([function(r){"use strict";function e(){var r=arguments;if(1==r.length)var p={init:i},s=r[0];else var p=r[0],s=r[1];var v={};-1!==[Error,EvalError,RangeError,ReferenceError,SyntaxError,TypeError,URIError].indexOf(p)&&(p=n(p,v));var y="function"==typeof p;s[a]=y?p[a]:p;var d=new s(p);v.name=d.name,!d[c]&&y&&(d[c]=function(){p.apply(this,arguments)});var l=function(){};l[a]=d;var m=d.name?d.name:"";if(d[c]===o||d[c]===i)var x=new Function("F","return function "+m+"(){return new F()}")(l);else var x=new Function("F","i","u","n","return function "+m+"(){ var x=new F(),r=i.apply(x,arguments)\nif(r===n)\nreturn x\nelse if(r===u)\nreturn n\nelse\nreturn r\n}")(l,d[c],e[u]);d.constructor=x;for(var g in d)t(x,d,g);for(var g in p)f.call(p,g)&&x[g]===o&&t(x,p,g);return x.parent=p,x[a]=d,x}function n(r,e){function n(){var n=new r(arguments[0]);return n.name=e.name,this.message=n.message,Object.defineProperty?Object.defineProperty(this,"stack",{get:function(){return n.stack}}):this.stack=n.stack,this}var t=function(){};return t.prototype=r.prototype,n.prototype=new t,n}function t(r,e,n){try{var t=Object.getOwnPropertyDescriptor(e,n);t.get!==o||t.get!==o&&Object.defineProperty!==o?Object.defineProperty(r,n,t):r[n]=e[n]}catch(i){}}var o,i=function(){},a="prototype",u="undefined",c="init",f={}.hasOwnProperty;e[u]={},r.exports=e}])});


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
var instanceA = new TypeScriptChildA("a");
var instanceB = new TypeScriptChildB("b");
for (var i = 0; i < 100000; i++) {
    instanceA.method();
    instanceB.method();
}
ready
ClassManager / Browser / Monomorphic
var instanceA = new CMBrowserMonoChildA("a");
var instanceB = new CMBrowserMonoChildB("b");
for (var i = 0; i < 100000; i++) {
    instanceA.method();
    instanceB.method();
}
ready
ClassManager / Browser / Polymorphic
var instanceA = new CMBrowserPolyChildA("a");
var instanceB = new CMBrowserPolyChildB("b");
for (var i = 0; i < 100000; i++) {
    instanceA.method();
    instanceB.method();
}
ready
ClassManager / Server / Monomorphic / Full
var instanceA = new CMServerFullrefMonoChildA("a");
var instanceB = new CMServerFullrefMonoChildB("b");
for (var i = 0; i < 100000; i++) {
    instanceA.method();
    instanceB.method();
}
ready
ClassManager / Server / Monomorphic / Partial
var instanceA = new CMServerPartialrefMonoChildA("a");
var instanceB = new CMServerPartialrefMonoChildB("b");
for (var i = 0; i < 100000; i++) {
    instanceA.method();
    instanceB.method();
}
ready
ClassManager / Server / Polymorphic / Partial
var instanceA = new CMServerPartialrefPolyChildA("a");
var instanceB = new CMServerPartialrefPolyChildB("b");
for (var i = 0; i < 100000; i++) {
    instanceA.method();
    instanceB.method();
}
ready
DotNetWise inheritWith
var instanceA = new DNW_IW_ChildA("a");
var instanceB = new DNW_IW_ChildB("b");
for (var i = 0; i < 100000; i++) {
    instanceA.method();
    instanceB.method();
}
ready
DotNetWise fastClass
var instanceA = new DNW_FC_ChildA("a");
var instanceB = new DNW_FC_ChildB("b");
for (var i = 0; i < 100000; i++) {
    instanceA.method();
    instanceB.method();
}
ready
Fiber
var instanceA = new FiberChildA("a");
var instanceB = new FiberChildB("b");
for (var i = 0; i < 100000; i++) {
    instanceA.method();
    instanceB.method();
}
ready
John Resig
var instanceA = new JRChildA("a");
var instanceB = new JRChildB("b");
for (var i = 0; i < 100000; i++) {
    instanceA.method();
    instanceB.method();
}
ready
Native
var instanceA = new NativeChildA("a");
var instanceB = new NativeChildB("b");
for (var i = 0; i < 100000; i++) {
    instanceA.method();
    instanceB.method();
}
ready
Proto
var instanceA = ProtoChildA("a");
var instanceB = ProtoChildB("b");
for (var i = 0; i < 100000; i++) {
    instanceA.method();
    instanceB.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