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
var methodAccessPerObject = 5;
var res = 0;
Klass1 = function() { var privateArr = []; }
Klass1.prototype.foo = function(x) {
return x + 1;
}
Klass1.prototype.bar = function(x) {
return x + 1;
}
Klass2 = function() {
var privateArr = [];
var foo = function(x) {
return x + 1;
},
bar = function(x) {
return x + 1;
};
return {foo: foo, bar: bar}
}
var FooFunction = function(x) {
return x + 1;
};
var BarFunction = function(x) {
return x + 1;
};
Klass3 = function() {
var privateArr = [];
return {foo: FooFunction, bar: BarFunction}
}
Klass4 = function() {
var privateArr = [];
this.foo = FooFunction;
this.bar = BarFunction;
}
Klass5 = function(){
var privateArr = [];
// let's use `bind` to partially apply, to provide
// access to the private variable. If not this, why else
// would anyone use the module pattern?
this.foo = FooFunction.bind(this, privateArr);
this.bar = BarFunction.bind(this, privateArr);
}
Klass6 = function() {
var privateArr = [];
return {
foo: FooFunction.bind(this, privateArr),
bar: BarFunction.bind(this, privateArr)
}
}
Ready to run.
Test | Ops/sec | |
---|---|---|
Prototypal |
| ready |
Module pattern |
| ready |
Module pattern with cached functions |
| ready |
Prototypal with cached |
| ready |
Prototypal with bound private |
| ready |
Module pattern with cached functions and bound private |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.