Open your terminal and run:
git clone [email protected]:typescript-tutorial/data-validation-benchmark.git
Make sure you have Node.js and npm installed. Then run:
npm install
Run the Benchmark with typescript directly:
npx tsx ./src/app.ts
Rank | Library | Ops/sec | RME (%) | Samples | Size (min+gz) | Relative Speed (vs fastest) | Times Slower than Ajv | Note |
---|---|---|---|---|---|---|---|---|
🥇 1 | Ajv | 6,091,923 | 0.76% | 100 | 📦 ~114 KB | 🏆 1.00× (fastest) | 🏆 1× | ⚡ Fastest + Heavier bundle |
🥈 2 | xvalidators | 1,246,188 | 1.29% | 92 | ⚡ ~3.8 KB | ~20.46% of Ajv | ~4.9× | 🔥 Very Fast + Small |
🥉 3 | Zod | 939,381 | 0.31% | 96 | 🧱 ~25 KB | ~15.42% of Ajv | ~6.5× | 🐇 Fast + Medium Size |
4 | Valibot | 859,490 | 0.24% | 95 | ⚡ ~4 KB | ~14.11% of Ajv | ~7.1× | 🐇 Fast + Small Size |
5 | Joi | 344,710 | 0.37% | 93 | 📦 ~80 KB | ~5.56% of Ajv | ~17.7× | 🐢 Slow + Heavy Size |
6 | Yup | 115,048 | 0.34% | 91 | 🧱 ~28 KB | ~1.89% of Ajv | ~52.9× | 🐢 Slowest + Medium Size + Frontend-oriented |
- Top performer with ~6.09 million ops/sec.
- Best for JSON Schema validation, high-throughput services.
- Ideal for performance-critical Node.js or edge runtimes.
- ~4.9x slower than Ajv, but ~1.3x faster than Zod, and even faster than Valibot.
- xvalidators is focused on bundle small size + performance, good for frontend.
- Excellent TypeScript inference, flexible custom rules.
- Very good for internal tools, low-code platforms, or apps that require typed validation
- Nearly similar in ops/sec, suggesting similar architecture or design trade-offs.
- Good for TypeScript-first developer experience but noticeably slower than Ajv/xvalidators.
- Both offer great DX.
- Valibot is focused on bundle size + performance, good for frontend.
- Zod still preferred if you need ecosystem maturity and developer ergonomics.
- Significantly slower, not suited for performance-sensitive applications.
- Useful in some backend contexts (Joi) or form validation (Yup), but not recommended when performance matters.
Use Case | Library | Reason |
---|---|---|
High-throughput backend APIs | Ajv | Fastest JSON Schema validator |
Minimal frontend apps with type-safe apps and custom rules | xvalidators | Good speed, excellent TypeScript integration |
Minimal frontend apps | Valibot | Lightweight and efficient |
DX-focused development | Zod | Clean syntax, popular, ideal for prototypes |
Legacy/enterprise backend apps | Joi | Powerful features, but low performance |
Form validation in React (Formik) | Yup | Integrated with form tools, but slow |
- If you need speed: → Ajv
- If you want typescript + good speed + small: → xvalidators
- If you prefer a big community support over speed: → Zod or Valibot
- If you already use Formik or legacy stack: → Yup or Joi