Some schema libraries support two way conversion of data, often referred to as "encoding" and "decoding".
We benchmark the time taken to encode and decode a Date to and from a string (usually an ISO 8601 string, but we don't enforce this).
Copy to clipboardimport * as z from "zod"; const dateFromString = z.codec(z.iso.datetime(), z.date(), { encode: (date) => date.toISOString(), decode: (str) => new Date(str), }); dateFromString.encode(new Date(0)); // "1970-01-01T00:00:00.000Z" dateFromString.decode("1970-01-01T00:00:00.000Z"); // Date
Invalid data
We don't benchmark codecs with invalid data, as many libraries require the input to be correctly typed before passing it to the codec.
Optimizations
| Library | Version | Downloads (/wk) | Optimizations | Encode | Decode | |||||
|---|---|---|---|---|---|---|---|---|---|---|
zod/mini | 4.4.3 | 185.36M | JIT | Code snippet | 876 ns | Code snippet | 594 ns | |||
zod | 4.4.3 | 185.36M | JIT | Code snippet | 917 ns | Code snippet | 598 ns | |||
typebox | Accepts unknown valuesThis codec allows unknown input, requiring extra validation. | 1.2.1 | 4.17M | JIT | Code snippet(Commented code is not benchmarked) | 5 μs | Code snippet(Commented code is not benchmarked) | 5 μs | ||
sury | 11.0.0-alpha.7 | 263.43K | JIT | Code snippet(Commented code is not benchmarked) | 524 ns | Code snippet(Commented code is not benchmarked) | 309 ns | |||
io-ts | 2.2.22 | 3.14M | None | Code snippet(Commented code is not benchmarked) | 512 ns | Code snippet(Commented code is not benchmarked) | 293 ns | |||
effect@beta (unknown) | Accepts unknown valuesThis codec allows unknown input, requiring extra validation. | 4.0.0-beta.78 | 19.4M | None | Code snippet(Commented code is not benchmarked) | 1 μs | Code snippet(Commented code is not benchmarked) | 719 ns | ||
effect@beta | 4.0.0-beta.78 | 19.4M | None | Code snippet(Commented code is not benchmarked) | 1 μs | Code snippet(Commented code is not benchmarked) | 716 ns | |||
effect | 3.21.3 | 19.4M | None | Code snippet | 1 μs | Code snippet | 927 ns | |||
effect (unknown) | Accepts unknown valuesThis codec allows unknown input, requiring extra validation. | 3.21.3 | 19.4M | None | Code snippet | 1 μs | Code snippet | 917 ns | ||