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
// Create an array with 1 million elements
const arraySize = 1000000;
const testArray = new Array(arraySize);
class ExtendedArray extends Array {
constructor() {
super();
this.map = new Map();
}
set(index, value) {
this.map.set(index, value);
}
get(index) {
return this.map.get(index);
}
}
Object.defineProperty(ExtendedArray.prototype, 'value', {
set(index, value) {
this.set(index, value);
},
get() {
return {
[Symbol.toPrimitive](hint) {
if (hint === 'number') {
return this.get(this);
}
},
};
},
});
// Create an array with 1 million elements
const testArray2 = new ExtendedArray(arraySize);
class ExtendedArray2 {
constructor() {
this.map = new Map();
return new Proxy(this, {
set: (target, prop, value) => {
if (!isNaN(prop)) {
target.map.set(Number(prop), value);
return true;
}
target[prop] = value;
return true;
},
get: (target, prop) => {
if (!isNaN(prop)) {
return target.map.get(Number(prop));
}
return target[prop];
}
});
}
}
const testArray3 = new ExtendedArray2(arraySize);
const map = new Map();
const objectArray = new Array(arraySize)
class ObjectTest {
index = 0;
set value(value) {
objectArray[this.index] = value;
}
get value() {
return objectArray[this.index];
}
}
const objectTest = new ObjectTest()
Ready to run.
Test | Ops/sec | |
---|---|---|
No proxy |
| ready |
Get/set proxy |
| ready |
ES6 Proxy |
| ready |
Plain map |
| ready |
Object proxy |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.