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 obj = generateRandomObject(5, 5);
let path = findRandomPrimitivePath(obj);
const str_obj=JSON.stringify(obj)
const f1text=`const obj=${str_obj};const ttt=obj.$path`
const f2text=`const obj=JSON.parse('${str_obj}');const ttt=obj.$path`
// -------------------
function generateRandomObject(maxWidth, maxDepth) {
const chars = 'abcdefghijklmnopqrstuvwxyz';
function randomKey() {
return chars[Math.floor(Math.random() * chars.length)] + Math.floor(Math.random() * 100);
}
function randomValue(depth) {
if (depth >= maxDepth || Math.random() < 0.3) {
return Math.random() < 0.5
? Math.floor(Math.random() * 1000)
: Math.random().toString(36).substring(2, 7);
} else {
return generateLevel(depth + 1);
}
}
function generateLevel(depth) {
const obj = {};
const width = Math.floor(Math.random() * maxWidth) + 1;
for (let i = 0; i < width; i++) {
obj[randomKey()] = randomValue(depth);
}
return obj;
}
return generateLevel(0);
}
function findRandomPrimitivePath(obj) {
const paths = [];
function traverse(current, path) {
if (typeof current !== 'object' || current === null) {
paths.push(path);
} else {
for (const key in current) {
traverse(current[key], path.concat(key));
}
}
}
traverse(obj, []);
if (paths.length === 0) return null;
const chosenPath = paths[Math.floor(Math.random() * paths.length)];
return chosenPath.join('.');
}
5path = findRandomPrimitivePath(obj);Ready to run.
| Test | Ops/sec | |
|---|---|---|
| eval | | ready |
| parse | | ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.