jsPerf.app is an online JavaScript performance benchmark test runner & jsperf.com mirror. It is a complete rewrite in homage to the once excellent jsperf.com now with hopefully a more modern & maintainable codebase.
jsperf.com URLs are mirrored at the same path, e.g:
https://jsperf.com/negative-modulo/2
Can be accessed at:
https://jsperf.app/negative-modulo/2
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.
*** IF CURRENT PAGE IS BROKEN - then visit repository for the link to proper version. ***
<script src="http://kogarashisan.github.io/PerfTests/export/dependencies-v2.js"></script>
<script src="http://kogarashisan.github.io/PerfTests/export/bundle-v2.js"></script>
<script>
// dependencies/defclass.js
function defclass(prototype) {
var constructor = prototype.constructor;
constructor.prototype = prototype;
return constructor;
}
function extend(constructor, properties) {
var prototype = Factory.prototype = constructor.prototype;
return defclass(new Factory(prototype, properties));
}
function Factory(prototype, properties) {
for (var property in prototype) {
if (prototype.hasOwnProperty(property)) {
var value = prototype[property];
if (typeof value === "function") property += "_";
this[property] = value;
}
}
for (var property in properties)
if (properties.hasOwnProperty(property))
this[property] = properties[property];
}
</script>
<script>
// src/defclass/main.js
var DefclassParent = defclass({
counter: 0,
instance_array: [],
instance_string: "",
constructor: function (instance_string) {
this.instance_string = instance_string;
},
method: function (prevent_inline) {
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 DefclassChildA = extend(DefclassParent, {
member_a: 1,
constructor: function (instance_string) {
this.constructor_(instance_string);
},
method: function () {
this.member_a =- this.member_a;
this.method_(false);
}
});
var DefclassChildB = extend(DefclassParent, {
member_b: -1,
constructor: function (instance_string) {
this.constructor_(instance_string);
},
method: function () {
this.member_b =- this.member_b;
this.method_(false);
}
});
</script>
<script>
/*
Each model exports two children into window, for example:
TypeScriptChildA and TypeScriptChildB
This code creates 5 instances of each child for each model
and stores them in global model_instances array.
Model test then can be done as follows:
var instances = model_instances[0]; // TypeScript
// just a large loop
for (var i = 0; i < 100000; i++) {
// call `method` on each of 10 different instances
for (var c = 0; c < 10; c++) {
instances[c].method();
}
}
*/
var model_names = [
/* 0 */'TypeScript',
/* 1 */'CMBrowserMono', // ClassManager
/* 2 */'CMBrowserPoly', // ClassManager
/* 3 */'CMServerFullrefMono', // ClassManager
/* 4 */'CMServerPartialrefMono', // ClassManager
/* 5 */'CMServerPartialrefPoly', // ClassManager
/* 6 */'DNW_IW_', // DotNetWise inheritWith
/* 7 */'DNW_FC_', // DotNetWise fastClass
/* 8 */'Fiber',
/* 9 */'JR', // John Resig
/* 10 */'NativeUnwrapped',
/* 11 */'NativeWrapped',
/* 12 */'Klass', // klass
/* 13 */'AugmentClassical', // augment
/* 14 */'Defclass' // defclass
];
var model_instances = [];
for (var model_index = 0; model_index < model_names.length; model_index++) {
var constructorA = window[model_names[model_index] + 'ChildA'];
var constructorB = window[model_names[model_index] + 'ChildB'];
model_instances[model_index] = [
new constructorA("a1"),
new constructorB("b1"),
new constructorA("a2"),
new constructorB("b2"),
new constructorA("a3"),
new constructorB("b3"),
new constructorA("a4"),
new constructorB("b4"),
new constructorA("a5"),
new constructorB("b5")
];
// warm-up loop
for (var dummy = 0; dummy < 5; dummy++) {
for (var c = 0; c < 10; c++) {
model_instances[model_index][c].method();
}
}
}
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
TypeScript |
| ready |
ClassManager / Browser / Monomorphic |
| ready |
ClassManager / Browser / Polymorphic |
| ready |
ClassManager / Server / Monomorphic / Full |
| ready |
ClassManager / Server / Monomorphic / Partial |
| ready |
ClassManager / Server / Polymorphic / Partial |
| ready |
DotNetWise inheritWith |
| ready |
DotNetWise fastClass |
| ready |
Fiber |
| ready |
John Resig |
| ready |
Native (unwrapped) |
| ready |
Native (wrapped) |
| ready |
klass |
| ready |
augment |
| ready |
defclass |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.