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
function isX(thing) {
return thing.type === 'x';
}
function doX(thing) {
return thing.value + 1;
}
function isY(thing) {
return thing.type === 'y';
}
function doY(thing) {
return thing.value + 'hello';
}
function isZ(thing) {
return thing.type === 'z';
}
function doZ(thing) {
return !thing.value;
}
const lookup = new Map([
['x', (thing) => {
if (isX(thing)) {
return doX(thing);
}
throw 'NOT X';
}],
['y', (thing) => {
if (isY(thing)) {
return doY(thing);
}
throw 'NOT Y';
}],
['z', (thing) => {
if (isZthing)) {
return doZ(thing);
}
throw 'NOT Z';
}]
]);
// populates either number, string or boolean
const things = [];
for (let i = 0; i < 100000; i++) {
const rand = Math.random();
if (rand <= 0.333) {
things.push({
type: 'x',
value: Math.random()
});
} else if (rand <= 0.666) {
things.push({
type: 'y',
value: Math.random().toString()
});
} else {
things.push({
type: 'z',
value: Math.random() > 0.5
});
}
}
Ready to run.
Test | Ops/sec | |
---|---|---|
Type Guard "Switch" |
| ready |
Map |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.