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
This test suite compares performances of pure “prototypal creation” and “functional creation”. Both patterns have been well explained by Douglas Crockford in his book: JavaScript, The Good Parts.
// Functional inheritance
var object = function () {
var that = {
prop: 'prop',
method: function () {
return that.prop;
}
};
return that;
};
// Prototypal inheritance
var inherits = function(Child, Parent) {
function F() { }
F.prototype = Parent.prototype;
Child.prototype = new F;
};
var Object = function () {};
Object.prototype.prop = 'prop';
Object.prototype.method = function () {
return this.prop;
};
// Prototypal inheritance where all functions are bound to this
var BObject = function () {
this.method = this.method.bind(this);
};
BObject.prototype.prop = 'prop';
BObject.prototype.method = function () {
return this.prop;
};
var o = object();
var O = new Object();
var B = new BObject();
Ready to run.
Test | Ops/sec | |
---|---|---|
object() |
| ready |
new Object() |
| ready |
obj.method() |
| ready |
O.method() |
| ready |
new BObject() |
| ready |
BOb.method() |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.