Published
Edited
Apr 3, 2022
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
pinnedResults = FileAttachment("results.json").json()
Insert cell
results = {
return Generators.observe((send) => {
if (usePinnedResults[0]) {
send(pinnedResults);
return;
}
const r = [];
const s = new Benchmark.Suite("splice");

persons.map(({ key, parser }) => {
s.add(key, function () {
parser.parse(people);
});
});

s.on("cycle", (e) => {
r.push(String(e.target));
send(r);
})
.on("finish", send(r))
.run();
});
}
Insert cell
Benchmark = require("benchmark")
Insert cell
zods = ({
"3.0.0": await import("zod@3.0.0"),
"3.10.0": await import("zod@3.10.0"),
"3.11.0": await import("zod@3.11.0"),
"3.12.0": await import("zod@3.12.0"),
"3.13.0": await import("zod@3.13.0"),
"3.14.0": await import("zod@3.14.0"),
"3.14.1": await import("zod@3.14.1"),
"3.14.2": await import("zod@3.14.2"),
"3.14.3": await import("zod@3.14.3")
})
Insert cell
persons = Object.entries(zods).map(([key, val]) => {
return {
key,
parser: person(val)
};
})
Insert cell
person(zods["3.0.0"]).parse(people)
Insert cell
people = {
let i = 0;
function array(fn) {
return Array.from({ length: ++i % 10 }, () => fn());
}
function str() {
return (++i % 100).toString(16);
}
function num() {
return ++i;
}
return Array.from({ length: 100 }, () => {
return {
type: "person",
hair: i % 2 ? "blue" : "brown",
active: !!(i % 2),
name: str(),
age: num(),
hobbies: array(str),
address: {
street: str(),
zip: str(),
country: str()
}
};
});
}
Insert cell
person = (z) =>
z.array(
z.object({
type: z.literal("person"),
hair: z.enum(["blue", "brown"]),
active: z.boolean(),
name: z.string(),
age: z.number().int(),
hobbies: z.array(z.string()),
address: z.object({
street: z.string(),
zip: z.string(),
country: z.string()
})
})
)
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more