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 deepFreeze(obj) {
const stack = [obj];
const visited = new WeakSet();
while (stack.length > 0) {
const current = stack.pop();
if (visited.has(current)) continue;
visited.add(current);
Object.freeze(current);
for (const key of Reflect.ownKeys(current)) {
const value = current[key];
if (
value !== null &&
(typeof value === "object" || typeof value === "function") &&
!Object.isFrozen(value)
) {
stack.push(value);
}
}
}
return obj;
}
function deepFreeze2(object) {
// Retrieve the property names defined on object
const propNames = Reflect.ownKeys(object);
// Freeze properties before freezing self
for (const name of propNames) {
const value = object[name];
if ((value && typeof value === "object") || typeof value === "function") {
deepFreeze(value);
}
}
return Object.freeze(object);
}
function cowFreeze(obj) {
return new Proxy(obj, {
set(target, prop, value) {
throw new Error("Immutable: cannot modify frozen object");
},
get(target, prop) {
const val = target[prop];
if (val && typeof val === "object") {
return cowFreeze(val); // lazily wrap nested objects
}
return val;
}
});
}
const selfRefObj = { foo: { bar: "baz" } };
selfRefObj.foo.self = selfRefObj;
const config = {
api: { url: "https://example.com", timeout: 5000 },
features: { cycle: selfRefObj, darkMode: true }
};
Ready to run.
| Test | Ops/sec | |
|---|---|---|
| Stack + WeakSet Cycle Detection | | ready |
| Recursively Freeze | | ready |
| Copy-on-write | | ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.