LiquidLava class system performance

JavaScript performance comparison

Revision 10 of this test case created by kogarashisan1

Preparation code

<!-- 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>
    

Preparation code output

<!-- Standalone version of ClassManager --> <!-- https://github.com/kogarashisan/ClassManager -->

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
Native child class creation
for (var i = 0; i < 10000; i++) {
    new NativeChildClass()
}
pending…
Lava child class creation (client generated class)
for (var i = 0; i < 10000; i++) {
    new LavaChildClass()
}
pending…
Lava child class creation (server-side generated class)
for (var i = 0; i < 10000; i++) {
    new LavaServerChild()
}
pending…
Native method call in child class
for (var i = 0; i < 20000; i++) {
    NativeInstance.method()
}
pending…
Lava method call in child class (client generated class)
for (var i = 0; i < 20000; i++) {
    LavaInstance.method()
}
pending…
Lava method call in child class (server generated class)
for (var i = 0; i < 20000; i++) {
    ServerInstance.method()
}
pending…

Compare results of other browsers

Revisions

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

0 Comments