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
Testing widely used inheritance libraries against Fiber.js and native javascript
<script src="http://code.jquery.com/jquery-1.9.1.min.js">
</script>
<script src="http://dl.dropbox.com/u/7677927/oop-benchmark/lib/jrclass.js">
</script>
<script src="http://dl.dropbox.com/u/7677927/oop-benchmark/lib/klass.js">
</script>
<script src="http://dl.dropbox.com/u/7677927/oop-benchmark/lib/classy.js">
</script>
<script src="http://dl.dropbox.com/u/7677927/oop-benchmark/lib/ptclass.js">
</script>
<script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.3.1/underscore-min.js">
</script>
<script src="//cdnjs.cloudflare.com/ajax/libs/backbone.js/0.9.0/backbone-min.js">
</script>
<script src="//ajax.googleapis.com/ajax/libs/mootools/1.3/mootools-yui-compressed.js">
</script>
<script src="//ajax.googleapis.com/ajax/libs/ext-core/3/ext-core.js">
</script>
<script src="http://kiro.me/temp/fiber.js">
</script>
<script>
Function.prototype.define = function(name, methods, proto) {
var ctor = this;
if (proto) {
var base = ctor.prototype = new proto();
ctor.prototype.constructor = ctor;
}
var p = ctor.prototype;
p[name] = p;
p.ctor = ctor;
p.m = methods.m;
//alert(p.m);
return ctor;
}
</script>
(function () {
var canDefineNonEnumerableProperty = typeof Object.defineProperty === "function";
function __() { };
Function.prototype.inherit = function (creator, makeConstructorNotEnumerable) {
/// <summary>Inherits the prototype of the given function. The creator function should return a new Constructor function whose prototype will share this functions's prototype</summary>
/// <param name="creator" type="Function">function(base, baseConstructor) {<br/>
/// return function Derived() { <br/>
/// base.apply(this, arguments); <br/>
/// } <br/>
/// Notice that there is no .override method call after the function Derrived(){}. This is very important. If you do want to override some methods then use .extend instead
/// </param>
/// <param name="makeConstructorNotEnumerable" type="Boolean">Object.defineProperty is rather slow. If you concern about performance and don't care about 'constructor' being enumerable in for (var i in instance) then let this false. <br/>
/// Otherwise set it to true and we will redefine the correct constructor i.e. Extendee.prototype.constructor === Extendee that is non-Enumerable
/// </param>
__.prototype = this.prototype;
var Derived = creator.call(this, this.prototype, this);
Derived.prototype = new __;
this.__class = Derived.__class = true;
//if we care about Extendee.prototype.constructor === Extendee to be non-Enumerable
//By default we set the constructor but we don't make it non-enumerable
if (makeConstructorNotEnumerable && canDefineNonEnumerableProperty)//this is not default as it carries over some performance overhead
Object.defineProperty(extendeePrototype, 'constructor', { enumerable: false, value: Derived });
else Derived.prototype.constructor = Derived;//Also fallback for older non-ECMA-5 browsers
return Derived;
};
Function.prototype.extend = function (creator) {
/// <summary>Extends the prototype of the given function. The creator function should return a new Constructor function whose prototype will share this functions's prototype.</summary>
/// <param name="creator" type="Function">function(base, baseConstructor) {<br/>
/// return function Derived() { <br/>
/// base.apply(this, arguments); <br/>
/// }.override(base, { //custom functions to be added on Derived.prototype <br/>
/// method: function() { <br/>
/// return base.method.apply(this, arguments); //call the base class' method, assuming is any <br/>
/// } <br/>
/// }); <br/>
/// So it is very important to call the .override at the end. If you simply want to inherit from an object with no overrides then you should call .inherit function instead
/// </param>
var Derived = creator.call(this, this.prototype, this);
this.__class = Derived.__class = true;
return Derived;
};
Function.prototype.define = function (prototype) {
/// <summary>Define members on the prototype of the given function with the custom methods and fields specified in the prototype parameter.</summary>
/// <param name="prototype" type="Plain Object">A custom object with the methods or properties to be added on Extendee.prototype</param>
var extendeePrototype = this.prototype;
if (prototype)
for (var p in prototype)
extendeePrototype[p] = prototype[p];
return this;
}
Function.prototype.override = function (basePrototype, prototype, makeConstructorNotEnumerable) {
/// <summary>Extends the prototype of the given function with the custom methods and fields specified in the prototype parameter.</summary>
/// <param name="prototype" type="Plain Object">A custom object with the methods or properties to be added on Extendee.prototype</param>
__.prototype = basePrototype;
var extendeePrototype = new __;
this.prototype = extendeePrototype;
//if we care about Extendee.prototype.constructor === Extendee to be non-Enumerable
//By default we set the constructor but we don't make it non-enumerable
if (makeConstructorNotEnumerable && canDefineNonEnumerableProperty)//this is not default as it carries over some performance overhead
Object.defineProperty(extendeePrototype, 'constructor', { enumerable: false, value: this });
else extendeePrototype.constructor = this;
if (prototype)
for (var p in prototype)
extendeePrototype[p] = prototype[p];
return this;
}
})();
Ready to run.
Test | Ops/sec | |
---|---|---|
John Resig's Class |
| ready |
Klass |
| ready |
Classy |
| ready |
Backbone.js |
| ready |
MooTools |
| ready |
ExtJS |
| ready |
PTClass (Prototype.js) |
| ready |
Fiber.js |
| ready |
Native |
| ready |
TypeScript |
| ready |
DotNetWise extend |
| ready |
DotNetWise extend - fix constructor |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.