Open your terminal and run:
git clone git@github.com: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) | Note |
---|---|---|---|---|---|---|---|
🥇 1 | Ajv | 2,484,057 | 3.83% | 78 | ~114 KB | 🏆 1.00× (fastest) | Fastest + Heavier bundle |
🥈 2 | xvalidators | 473,929 | 3.66% | 85 | ~3.8 KB | ~19.1% of Ajv | Very Fast + Small |
🥉 3 | Valibot | 208,463 | 3.07% | 78 | ~4 KB | ~8.4% of Ajv | Fast + Small Size |
4 | Zod | 187,866 | 7.54% | 69 | ~25 KB | ~7.6% of Ajv | Fast + Medium Size |
5 | Joi | 49,806 | 3.49% | 79 | ~80 KB | ~2.0% of Ajv | Slow + Heavy Size |
6 | Yup | 30,993 | 5.2% | 76 | ~28 KB | ~1.2% of Ajv | Slowest + Medium Size + Frontend-oriented |
- Top performer with ~2.48 million ops/sec.
- Best for JSON Schema validation, high-throughput services.
- Ideal for performance-critical Node.js or edge runtimes.
- ~5.2x slower than Ajv, but ~2.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