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
<script src="http://dl.dropbox.com/u/7677927/oop-benchmark/lib/jrclass.js"></script>
<script src="http://raptorjs.org/dist/raptor.min.js" type="text/javascript"></script>
<script>
var augment = (function (bind, call) {
"use strict";
var bindable = Function.bindable = bind.bind(bind);
var callable = Function.callable = bindable(call);
var arrayFrom = Array.from = callable(Array.prototype.slice);
var ownPropertyOf = Object.ownPropertyOf = callable(Object.hasOwnProperty);
//Object.defineProperty(Function.prototype, "augment", augmentDescriptor);
Object.defineProperty(Object.prototype, "augment", { value: augment });
return callable(augment);
function augment(body) {
var base = typeof this === "function" ? this.prototype : this;
var prototype = Object.create(base);
body.apply(prototype, arrayFrom(arguments, 1).concat(base));
if (!ownPropertyOf(prototype, "constructor")) return prototype;
var constructor = prototype.constructor;
constructor.prototype = prototype;
return constructor;
}
}(Function.bind, Function.call));
Function.prototype.new = function () {
function functor() { return constructor.apply(this, args); }
var args = Array.prototype.slice.call(arguments);
functor.prototype = this.prototype;
var constructor = this;
return new functor;
};
function inherit() {
var len = arguments.length;
var parent = (len > 1) ? arguments[0] : Function.constructor;
var body = arguments[len - 1];
body.prototype = parent.prototype;
var constructor = new body(parent.prototype);
constructor.init.prototype = constructor;
return constructor.init;
}
</script>
<script>
(function(){function u(){}function f(){}var i=typeof global!="undefined",r,o,y;String.prototype.format||(r={},String.prototype.format=function(){for(var t=this,i=arguments,n=i.length;--n>=0;)t=t.replace(r[n]||(r[n]=RegExp("\\{"+n+"\\}","gm")),i[n]);return t},String.format||(String.format=function(n){for(var i=arguments,t=i.length;--t;)n=n.replace(r[t-1]||(r[t-1]=RegExp("\\{"+(t-1)+"\\}","gm")),i[t]);return n}));var t=Function.prototype,l=Array.prototype,e=l.forEach,a=Object.defineProperty,v=typeof Object.defineProperties=="function",n={};if(n=n.__proto__===Object.prototype,n)try{n={},n.__proto__={Object:1},n=n.Object===1}catch(b){n=!1}if(typeof Object.getPrototypeOf!="function"&&(Object.getPrototypeOf=n?function(n){return n.__proto__}:function(n){return n==null||!n.constructor||n===Object.prototype?null:n.constructor.prototype===n?Object.prototype:n.constructor.prototype}),e||(l.forEach=e=function(n,t){for(var i=0,r=this.length;i<r;++i)n.call(t||this,this[i],i,this)}),t.fastClass=function(n){var f=this,e=this.prototype,u,r;return n=n||function(){this.constructor=function(){f.apply(this,arguments)}},n.prototype=e,u=new n(e,this),u.hasOwnProperty("constructor")||(u.constructor=function(){f.apply(this,arguments)}),r=u.constructor,r.prototype=u,n=null,arguments.length>1&&t.define.apply(r,arguments),r.constructor=r,r},t.inheritWith=n?function(n){var u=this,r=(typeof n=="function"?n.call(this,this.prototype,this):n)||{},i=r.hasOwnProperty("constructor")?r.constructor:function(){u.apply(this,arguments)};return i.prototype=r,r.__proto__=this.prototype,n=null,arguments.length>1&&t.define.apply(i,arguments),i.constructor=i,i}:function(n){var e=this,r=(typeof n=="function"?n.call(this,this.prototype,this):n)||{},f=r.hasOwnProperty("constructor")?r.constructor:function(){e.apply(this,arguments)},o;return u.prototype=this.prototype,f.prototype=o=new u,n=r,t.define.apply(f,arguments),f.constructor=f,f},t.define=function(n,t){var f=this,r=this.prototype,s=n,o;if(n){typeof n=="function"&&(n=n.call(r,this.prototype,this));for(o in n)r[o]=n[o]}return n=null,(arguments.length>2||t)&&(r.hasOwnProperty("__mixins__")||(v?a(r,"__mixins__",{enumerable:!1,value:[],writeable:!1}).__mixins__.__hidden=!0:r.__mixins__=[]))&&e.call(arguments,function(n,t,e,o){if(o=typeof n=="function",o?(u.prototype=n.prototype,e=new n(r,f)):e=n,e){o&&r.__mixins__.push(n);for(var s in e)s!="constructor"&&s!="prototype"&&(r[s]=e[s])}}),this},Function.define=function(n,r){var f,u=n||function(){},e=arguments.length>1;return typeof n!="function"?(u=n.hasOwnProperty("constructor")?n.constructor:function(){},u.prototype=n,e=!0):(n=r,r=null),e&&t.define.apply(u,arguments),f=function(){Function.initMixins(this),u.apply(this,arguments)},f.prototype=u.prototype,f.constructor=f.prototype.constructor=u.constructor=u.prototype.constructor=f,f},t.defineStatic=function(n){if(n)for(var t in n)this[t]=n[t];return this},f.defineStatic({abstract:!0}),Function.abstract=function(n,t){var r=n||t?function(){typeof n=="function"&&n.apply(this,arguments),typeof t=="function"&&t.apply(this,arguments),typeof n=="string"||f()}.defineStatic({abstract:!0}):f;return r},Function.initMixins=function(t){if(t&&!t.__initMixins__){var r=t,e,o,u,f,s={};for(t.__initMixins__=1;r;)if(r=n?r.__proto__:Object.getPrototypeOf(r),r&&r.hasOwnProperty("__mixins__")&&(e=r.__mixins__)&&(o=e.length))for(u=0;f=e[u],u<o;u++)f in s||(s[f]=1,f.call(t,r,r.constructor));delete t.__initMixins__}},v){o={0:[Function,"initMixins","define","abstract"],1:[t,"fastClass","inheritWith","define","defineStatic"]};for(y in o)for(var s=o[y],p=s[0],h=1,c;c=s[h],h<s.length;h++)a(p,c,{enumerable:!1,value:p[c]})}})();
//# sourceMappingURL=FastClass.min.js.map
</script>
var InheritPerson = inherit(function () {
this.init = function(name) {
this.nome = name;
};
this.setAddress = function(country, city, street) {
this.country = country;
this.city = city;
this.street = street;
};
});
var InheritFrenchGuy = inherit(InheritPerson, function(base) {
this.init = function (name) {
base.init(name);
};
this.setAddress = function(city, street) {
base.setAddress("France", city, street);
};
});
var InheritParisLover = inherit(InheritFrenchGuy, function(base) {
this.init= function (name) {
base.init(name);
};
this.setAddress = function(street) {
base.setAddress("Paris", street);
return this;
};
});
var AugmentPerson = Object.augment(function() {
this.constructor = function (name) {
this.nome = name;
};
this.setAddress = function(country, city, street) {
this.country = country;
this.city = city;
this.street = street;
};
});
var AugmentFrenchGuy = AugmentPerson.augment(function(base) {
this.constructor = function (name) {
base.constructor(name);
};
this.setAddress = function(city, street) {
base.setAddress("France", city, street);
};
});
var AugmentParisLover = AugmentFrenchGuy.augment(function(base) {
this.constructor = function (name) {
base.constructor(name);
};
this.setAddress = function(street) {
base.setAddress("Paris", street);
return this;
};
});
var JRPerson = JRClass.extend({
init: function(name) {
this.name = name;
},
setAddress: function(country, city, street) {
this.country = country;
this.city = city;
this.street = street;
}
});
var JRFrenchGuy = JRPerson.extend({
init: function(name) {
this._super(name);
},
setAddress: function(city, street) {
this._super('France', city, street);
}
});
var JRParisLover = JRFrenchGuy.extend({
init: function(name) {
this._super(name);
},
setAddress: function(street) {
this._super('Paris', street);
return this;
}
});
var RaptorPerson = define.Class({
init: function(name) {
this.name = name;
},
setAddress: function(country, city, street) {
this.country = country;
this.city = city;
this.street = street;
}
});
var RaptorFrenchGuy = define.Class({superclass: RaptorPerson}, ['super'], function($super) {
var superCtor = $super.constructor;
var superSetAddress = $super.setAddress;
function RaptorFrenchGuy(name) {
superCtor.call(this, name);
};
RaptorFrenchGuy.prototype = {
setAddress: function(city, street) {
superSetAddress.call(this, 'France', city, street);
}
}
return RaptorFrenchGuy;
});
var RaptorParisLover = define.Class({superclass: RaptorFrenchGuy}, ['super'], function($super) {
var superCtor = $super.constructor;
var superSetAddress = $super.setAddress;
function RaptorParisLover(name) {
superCtor.call(this, name);
};
RaptorParisLover.prototype = {
setAddress: function(street) {
superSetAddress.call(this, 'Paris', street);
return this;
}
}
return RaptorParisLover;
});
var FCPerson = Function.inheritWith(function() {
return {
constructor: function(name) {
this.nome = name;
},
setAddress: function(country, city, street) {
this.country = country;
this.city = city;
this.street = street;
}
}
});
var FCFrenchGuy = FCPerson.inheritWith(function(base, baseCtor){
return {
constructor: function(name) {
baseCtor.call(this, name);
},
setAddress: function(city, street) {
base.setAddress('France', city, street);
}
}
});
var FCParisLover = FCFrenchGuy.inheritWith(function(base, baseCtor){
return {
constructor: function(name) {
baseCtor.call(this, name);
},
setAddress: function(street) {
base.setAddress('Paris', street);
return this;
}
}
});
Ready to run.
Test | Ops/sec | |
---|---|---|
inherit.js |
| ready |
augment.js |
| ready |
john resig |
| ready |
raptor |
| ready |
FastClass |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.