The goal is to compare different libraries and approaches to validate data in a TypeScript ecosystem.
It's interesting to see how each library is designed, how it's used, and how it performs.
Ideally you can use this comparison to choose the library that fits your needs the best.
Make sure you have Bun v1.1.x then :
# install the dependencies
bun install
# run each file once just to verify that everything is working as expected
bun check:once
# run the benchmarks
bun bench
At the time of writing, Node 22 is around 2 times slower than Bun v1 ^^'
Here are the library used in this comparison :
- arktype from David Blass
- suretype from Gustaf Räntilä
- valibot from Fabian Hiller
- zod from Colin McDonnell
- zod/mini from Colin McDonnell
Date | Score | Library | Deps | Size | Light | Input A | Input B | Throw | Safe | Script exec | Lib exec | Fast | Readability |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
2025-04-27 | 2 | ArkType | 2 | 151 KB | 0 | 1 | 1 | 0 | 1 | 866 ms -1 | 722 ms -1 | 0 | 1 |
2025-04-27 | 1 | Suretype | 3 | 195 KB | 0 | 0 | 0 | 1 | 1 | 2444 ms -1 | 2326 ms -1 | 0 | 1 |
2025-04-27 | 8 | Valibot | 0 | 6 KB | 1 | 1 | 1 | 1 | 1 | 68 ms 1 | 10 ms 1 | 1 | 0 |
2025-04-27 | 4 | @zod/mini | 1 | 21 KB | 1 | 1 | 0 | 1 | 1 | 211 ms 0 | 133 ms 0 | 0 | 0 |
2025-04-27 | 8 | Zod v3 | 0 | 60 KB | 0 | 1 | 1 | 1 | 1 | 97 ms 1 | 32 ms 1 | 1 | 1 |
2025-04-27 | 5 | Zod v4 | 1 | 50 KB | 0 | 1 | 1 | 1 | 1 | 221 ms 0 | 148 ms 0 | 0 | 1 |
Legend :
- Deps : the number of dependencies of the library
- Size : the minified build size in kilobytes of the related
.ts
file insrc
, runbun run build
to see by yourself - Light : 1 point if the build is
<= 20 KB
- Input A : 1 point if the library can see that
age
isoptional, number
intype UserInput
butnot optional, number
intype User
the output type - Input B : 1 point if the library can see that
phone
isoptional, string or number
intype UserInput
butnot optional, string
intype User
the output type - Throw : 1 point if the library have a parse or throw method, useful when we don't want to handle the error cases
- Safe : 1 point if the library have a safe parse method that will not throw and usually return a
Result
type - Script exec : 1 point if the average time in ms to execute the test file with bun is
<= 100ms
, check thebun run bench
command output - Lib exec : 1 point if the average time in ms to execute the library is
<= 35ms
, check thebun run check:once
command output - Fast : 1 point if the library execution time is less than 100 ms
- Readability : 1 point if the library is easy to write & read, the syntax need to be intuitive
Test have been run on :
- Windows 11 x64
- AMD Ryzen 7 7800X3D, 64GB of RAM
- Bun v1.2.4
Zod is my favorite pick because it's fast and provide a better readability.
Ok the build size is bigger but it does not impact the performance that much.
The 35ms vs 11ms seems like a 3x difference but it's the time to run 1000 iterations. So in the end it's not that much of a difference in a real world scenario.
- For some weird reason Zod v4 seems to be slower than Zod v3
- Zod mini not handling the
or
operator is a blocker to me, hopefully it will be added in the future
- vanilla version ?
- check error messages
- check custom error messages
- check custom validation rules
- check the perf without using
console
There are many ways to contribute to this project :
- Add a new library to the comparison
- Improve the comparison table, criteria, or scoring
- Improve the samples in
src
- Find a way to enhance library isolation to have more meaningful benchmarks
- Whatever you think that could be useful, check the above todo list for inspiration
Just open an issue or a PR, I'll be happy to discuss it with you <3
- Arktype : for making this comparison possible
- Bun : for their great tool to do almost everything ^^
- Github : for all their great work year after year, pushing OSS forward
- Repo-checker : eslint cover /src code and this tool the rest ^^
- Shields.io : for the nice badges on top of this readme
- Valibot : for making this comparison possible
- Zod : for making this comparison possible