moltar / Typescript Runtime Type Benchmarks
Programming Languages
Projects that are alternatives of or similar to Typescript Runtime Type Benchmarks
📊 Benchmark Comparison of Packages with Runtime Validation and TypeScript Support
⚠️ Note: Until #497 is resolved, some of the benchmarks in this repo are comparing apples-to-oranges due to the different APIs provided by validation libraries. Libraries which provide more functionality (like transformations, coercions, detailed errors) might be penalized for slower performance for those extra features.
Packages Compared
- bueno
- class-validator + class-transformer
- computed-types
- decoders
- io-ts
- jointz
- json-decoder
- marshal
- myzod
- purify-ts
- rulr
- runtypes
- simple-runtypes
- superstruct
- toi
- ts-json-validator
- ts-utils
- valita
- yup
- zod
Criteria
Validation
These packages are capable of validating the data for type correctness.
E.g. if string
was expected, but a number
was provided, the validator should fail.
Interface
It has a validator function or method that returns a valid type casted value or throws.
const data: any = {}
// `res` is now type casted to the right type
const res = isValid(data)
Or it has a type guard function that in a truthy block type casts the value.
const data: any = {}
function isMyDataValid(data: any) {
// isValidGuard is the type guard function provided by the package
if (isValidGuard(data)) {
// data here is "guarded" and therefore inferred to be of the right type
return data
}
throw new Error('Invalid!')
}
// `res` is now type casted to the right type
const res = isMyDataValid(data)
Benchmark Results
Data Type Checks
JSON, CSV, SVG)
Node 10.x (JSON, CSV, SVG)
Node 12.x (JSON, CSV, SVG)
Node 13.x (JSON, CSV, SVG)
Node 14.x (Data Type Checks Sans Outliers
Because some packages are so performant it makes it difficult to see the benchmarks for other packages.
This benchmark run includes all of the above packages, but excludes marshal
and ts-json-validator
.