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
// Keep a native baseline
const NativePromise = window.Promise;
// Your subclass
class FAKEPROMISE extends Promise {
constructor(executor) {
super(executor);
// Capturing a stack is intentionally expensive—this is what you want to measure
this.__creationPoint = new Error();
}
}
const FakePromise = FAKEPROMISE;
class FAKEPROMISEWITHSUPER extends Promise {
constructor(executor) {
super(executor);
}
}
const FakePromiseWithSuper = FAKEPROMISEWITHSUPER;
class FAKEPROMISENOSUPER extends Promise {}
const FakePromiseNoSuper = FAKEPROMISENOSUPER;
// Helper: create N promises of constructor form and resolve them immediately
function batchConstructor(P, n, done) {
let remaining = n;
for (let i = 0; i < n; i++) {
new P(res => res(i)).then(() => {
if (--remaining === 0) done();
});
}
}
// Helper: create N promises of resolve+then form
function batchResolveThen(P, n, done) {
let remaining = n;
for (let i = 0; i < n; i++) {
P.resolve(i).then(() => {
if (--remaining === 0) done();
});
}
}
const N = 1000; // adjust if runs take too long/short
Ready to run.
| Test | Ops/sec | |
|---|---|---|
| Native (constructor form) | | ready |
| Fake (constructor form) | | ready |
| Native (Promise.resolve().then) | | ready |
| Fake (Promise.resolve().then) | | ready |
| Native Promise.all | | ready |
| Fake Promise.all | | ready |
| Super only | | ready |
| No super / bare extends | | ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.