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
Filtering the highest priority duplicate from a list of duplicate json objects (duplicated on primary key)
// Generate ~Dynamics-style GUID
function generateGuid() {
if (typeof crypto !== "undefined" && crypto.randomUUID) {
return crypto.randomUUID(); // native, good randomness
}
// Fallback: 8-4-4-4-12 hex pattern
const hex = () => Math.floor(Math.random() * 0x10000).toString(16).padStart(4, "0");
return (
hex() + hex() + "-" +
hex() + "-" +
hex() + "-" +
hex() + "-" +
hex() + hex() + hex()
);
}
function randomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
// Fisher–Yates shuffle
function shuffle(array) {
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
return array;
}
function generateItems(count = 40000) {
const items = [];
const usedKeys = new Set();
const getUniqueGuid = () => {
let id;
do {
id = generateGuid();
} while (usedKeys.has(id));
usedKeys.add(id);
return id;
};
while (items.length < count) {
const remaining = count - items.length;
// how many times this primaryKey will appear (1–4, but not exceeding remaining slots)
const occurrences = Math.min(remaining, randomInt(1, 4));
const primaryKey = getUniqueGuid();
// pick unique priorities 1–4, no duplicates per key
const priorities = shuffle([1, 2, 3, 4]).slice(0, occurrences);
for (let i = 0; i < occurrences; i++) {
items.push({
primaryKey,
priority: priorities[i]
});
}
}
// Randomise final order
shuffle(items);
return items;
}
// Example usage:
const baseItems = generateItems(40000);
Ready to run.
| Test | Ops/sec | |
|---|---|---|
| Double Sort | | ready |
| ChatGPT Oneshot (Simple Map) | | ready |
| Sort first, compare, then write to dict | | ready |
| ChatGPT (Improve it) | | ready |
| ChatGPT (Improve it AGAIN) | | ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.