LiquidLava class system performance (v10)

Revision 10 of this benchmark created by kogarashisan1 on


Description

Performance of LiquidLava generated classes is comparable to their hand-written analogues.

Preparation HTML

<!-- Standalone version of ClassManager -->
<!-- https://github.com/kogarashisan/ClassManager -->
<script src="https://dl.dropboxusercontent.com/u/3554716/jsperf/lava-class-manager.js"></script>

<script>
///////////////////////////////////////////////////////////////////
// create classes in traditional way

function NativeParentClass() { this.counter = 0; }
NativeParentClass.prototype.method = function() { this.counter++; }

function NativeChildClass() {}
NativeChildClass.prototype = new NativeParentClass();
NativeChildClass.prototype.method = function() {
    NativeParentClass.prototype.method.call(this);
}

var NativeInstance = new NativeChildClass();

///////////////////////////////////////////////////////////////////
// Create classes via Lava.ClassManager

Lava.ClassManager.registerRootNamespace('window', window);
Lava.ClassManager.define(
'window.LavaParentClass',
{
    counter: 0,
    method: function() { this.counter++; }
});

Lava.ClassManager.define(
'window.LavaChildClass',
{
    Extends: 'window.LavaParentClass',
    method: function() { this.LavaParentClass$method(); }
});

var LavaInstance = new LavaChildClass();

///////////////////////////////////////////////////////////////////
// the same classes, but generated on server

Lava.ClassManager.loadClass({
        name: "LavaServerParent",
        path: "window.LavaServerParent",
        level: 0,
        "extends": null,
        "implements": [],
        hierarchy_paths: ["window.LavaServerParent"],
        parent_class_data: null,
        prototype_generator: function(cd,p) {
                var r=cd.references,
                        s=cd.shared;
                        p.Class = cd;
                        p.counter = 0;
                        p.method = r[0];
        },
        shared: {},
        references: [function () { this.counter++; }],
        constructor: function() {}
});

Lava.ClassManager.loadClass({
        name: "LavaServerChild",
        path: "window.LavaServerChild",
        level: 1,
        "extends": "window.LavaServerParent",
        "implements": [],
        hierarchy_paths: [
                "window.LavaServerParent",
                "window.LavaServerChild"
        ],
        parent_class_data: null,
        prototype_generator: function(cd,p) {
                var r=cd.references,
                        s=cd.shared;
                        p.Class = cd;
                        p.method = r[1];
                        p.counter = 0;
                        p.LavaServerParent$method = r[0];
        },
        shared: {},
        references: [function () { this.LavaServerParent$method(); }],
        constructor: function() {}
});

var ServerInstance = new LavaServerChild();
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Native child class creation
for (var i = 0; i < 10000; i++) {
    new NativeChildClass()
}
ready
Lava child class creation (client generated class)
for (var i = 0; i < 10000; i++) {
    new LavaChildClass()
}
ready
Lava child class creation (server-side generated class)
for (var i = 0; i < 10000; i++) {
    new LavaServerChild()
}
ready
Native method call in child class
for (var i = 0; i < 20000; i++) {
    NativeInstance.method()
}
ready
Lava method call in child class (client generated class)
for (var i = 0; i < 20000; i++) {
    LavaInstance.method()
}
ready
Lava method call in child class (server generated class)
for (var i = 0; i < 20000; i++) {
    ServerInstance.method()
}
ready

Revisions

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

  • Revision 3: published by kogarashisan1 on
  • Revision 9: published by Vyacheslav Egorov on
  • Revision 10: published by kogarashisan1 on