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>
//https://github.com/Josenzo/inherit.js
var inherit=function(){"use strict";function h(a,b){return"object"==typeof a?(d=new Function,d[e]=a):(d=a,a[e].hasOwnProperty(f)&&a[e][f]!==a||(d[e]="object"==typeof b?new a(b,b[f]):new a)),d}function i(c,d){a=g(c);for(b in d)a[b]=d[b];return a}var a,b,c,d,e="prototype",f="constructor",g=Object.create;return function j(a,b){var k=arguments;return k.length>2?(Array.prototype.splice.call(k,0,2,j(a,b)),j.apply(this,k)):(c=h(1==k.length?{}:a),d=h(k[k.length-1],g(c[e])),d[e].hasOwnProperty(f)||(d[e][f]=new Function),d[e][f][e]=i(c[e],d[e]),d[e][f].$super=g(c[e]),d[e][f][e][f]=d[e][f],d[e][f])}}();
var InheritParent = inherit(function () {
this.constructor = function (instance_string) {
this.counter = 0;
this.instance_array = [];
this.instance_string = instance_string;
};
this.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 InheritChildA = inherit(InheritParent, function ($super, $superC) {
this.constructor = function (instance_string) {
this.member_a = 1;
$superC(instance_string);
};
this.method = function () {
this.member_a =- this.member_a;
$super.method(false);
};
});
var InheritChildB = inherit(InheritParent, function ($super, $superC) {
this.constructor = function (instance_string) {
this.member_b =- 1;
$superC(instance_string);
};
this.method = function () {
this.member_b =- this.member_b;
$super.method(false);
};
});
/*
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
"Inherit"
];
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 |
Inherit |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.