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
When instantiating objects of the same class, is it faster to use the new keyword or just object literals?
function TestConstructor() {
this.test = true;
this.animal = 'monkey';
this.number = 8000;
}
function testFactory() {
return {
test: true,
animal: 'monkey',
number: 8000
};
}
function TestConstructorWithParams(test, animal, number) {
this.test = test;
this.animal = animal;
this.number = number;
}
function testFactoryWithParams(test, animal, number) {
return {
test: test,
animal: animal,
number: number
}
}
Ready to run.
Test | Ops/sec | |
---|---|---|
new |
| ready |
object literal |
| ready |
new + params |
| ready |
factory + params |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.