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
Test which way of creation object by given constructor and ARRAY of arguments are faster: + Fake constructor creation; + Function.prototype.bind method
function MyClass(a,b,c) {
this.a = a;
this.b = b;
this.c = c;
}
function create1(ctor, args){
function Service(){};
Service.prototype = ctor.prototype;
var s = new Service();
ctor.apply(s, args);
return s;
}
function create2(ctor, args) {
return new (Function.prototype.bind.apply(ctor, [null].concat(args)));
}
function create3(ctor, args) {
var i = Object.create(ctor.prototype)
, r = ctor.apply(i, args);
return r != null && (typeof r == 'object' || typeof r == 'function') ? r : i;
}
Ready to run.
Test | Ops/sec | |
---|---|---|
Fake constructor |
| ready |
Function.prototype.bind |
| ready |
Object.create (pretty similar to Fake constructor) |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.