baseline vs @sthir/runtime-checker vs zod (v2)

Revision 2 of this benchmark created on


Setup

window.t = get("https://unpkg.com/@sthir/runtime-checker/dist/sthir-runtime-checker.cjs.prod.js")
window.z = get("https://unpkg.com/zod/lib/index.umd.js")

function get(url) {
  let req = new XMLHttpRequest(); req.open("GET", url, false); req.send()
  return new Function("let module = { exports: {} };\nlet exports = module.exports;\n" + req.response + ";\nreturn module.exports")()
}

Test runner

Ready to run.

Testing in
TestOps/sec
baseline
const isUser = x =>
  typeof x === "object" && x !== null &&
  typeof x.name === "string" &&
  typeof x.email === "string" && x.email.includes("@")

isUser({ name: "Devansh", email: "foo" })
ready
@sthir/runtime-checker
const t = window.t
const isUser = x =>
  t.is(x, t.object({
    name: t.string,
    email: t.then(t.string, t.predicate(s => s.includes("@")))
  }))
  
isUser({ name: "Devansh", email: "foo" })
ready
zod
const z = window.z
const isUser = x =>
  z.object({
    name: z.string(),
    email: z.string().refine(s => s.includes("@"))
  }).safeParse(x).success

isUser({ name: "Devansh", email: "foo" })
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.