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
const $softPrivate = Symbol();
class SoftPrivateClass {
[$softPrivate] = 0;
add() {
this[$softPrivate] += 1;
}
get() {
return this[$softPrivate];
}
}
const hardMap = new WeakMap()
class HardPolyfillClass {
constructor() {
hardMap.set(this, 0);
}
add() {
hardMap.set(this, hardMap.get(this) + 1)
}
get() {
return hardMap.get(this);
}
}
class HardPrivateClass {
#hardPrivate = 0;
add() {
this.#hardPrivate += 1;
}
get() {
return this.#hardPrivate;
}
}
function runSoft() {
const sc = new SoftPrivateClass();
for (let i = 0; i < 10000; ++i) {
sc.add();
}
console.assert(sc.get() === 10000);
}
function runHardPolyfill() {
const hc = new HardPolyfillClass();
for (let i = 0; i < 10000; ++i) {
hc.add();
}
console.assert(hc.get() === 10000);
}
function runHard() {
const hc = new HardPrivateClass();
for (let i = 0; i < 10000; ++i) {
hc.add();
}
console.assert(hc.get() === 10000);
}
Ready to run.
Test | Ops/sec | |
---|---|---|
Soft Private |
| ready |
Hard Private |
| ready |
Hard Private (Polyfill) |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.