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 generatePoints(count = 10000, min = 0, max = 300) {
const points = new Array(count);
const range = max - min + 1;
for (let i = 0; i < count; i++) {
points[i] = {
x: Math.floor(Math.random() * range) + min,
y: Math.floor(Math.random() * range) + min
};
}
return points;
}
function buildPointIndex(points, keyCreator) {
const index = new Set();
for (const p of points) {
index.add(keyCreator(p));
}
return index;
}
function toIndexedArray(array, keyCreator) {
let result = {
index: new Set(),
keyCreator,
check(value) {
return this.index.has(this.keyCreator(value))
}
};
for (const arrayItem of array) {
result.index.add(keyCreator(arrayItem));
}
return result;
}
var mainArr = generatePoints();
var mainSet = toIndexedArray(mainArr, (p) => p.x + "," + p.y);
var mainSet2 = toIndexedArray(mainArr, (p) => p.x + p.y*1000);
var mainSet3 = toIndexedArray(mainArr, (p) => (p.x | (p.y << 10)));
var mainSet4 = toIndexedArray(mainArr, (p) => ((p.y << 16) | p.x) >>> 0);
var arrToCheck = generatePoints();Ready to run.
| Test | Ops/sec | |
|---|---|---|
| Array.Find | | ready |
| Set.has string key | | ready |
| Set.has intkey | | ready |
| Set.has binary shift key | | ready |
| Set.has Uint32 key | | ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.