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 bigint to and from a string.
Copy to clipboardimport * as z from "zod"; const bigIntFromString = z.codec(z.bigint(), z.string(), { encode: (bigint) => bigint.toString(), decode: (str) => BigInt(str), }); bigIntFromString.encode(1234567890123456789n); // "1234567890123456789" bigIntFromString.decode("1234567890123456789"); // 1234567890123456789n
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 | |||||
|---|---|---|---|---|---|---|---|---|---|---|
effect | 3.22.0 | 24.13M | None | Code snippet | 365 ns | Code snippet | 437 ns | |||
effect (unknown) | Accepts unknown valuesThis codec allows unknown input, requiring extra validation. | 3.22.0 | 24.13M | None | Code snippet | 378 ns | Code snippet | 439 ns | ||
effect@beta | 4.0.0-beta.98 | 24.13M | None | Code snippet(Commented code is not benchmarked) | 2 μs | Code snippet(Commented code is not benchmarked) | 2 μs | |||
effect@beta (unknown) | Accepts unknown valuesThis codec allows unknown input, requiring extra validation. | 4.0.0-beta.98 | 24.13M | None | Code snippet(Commented code is not benchmarked) | 2 μs | Code snippet(Commented code is not benchmarked) | 2 μs | ||
io-ts | 2.2.22 | 2.72M | None | Code snippet(Commented code is not benchmarked) | 82 ns | Code snippet(Commented code is not benchmarked) | 131 ns | |||
sury | 11.0.0-alpha.10 | 286.81K | JIT | Code snippet(Commented code is not benchmarked) | 82 ns | Code snippet(Commented code is not benchmarked) | 119 ns | |||
typebox | Accepts unknown valuesThis codec allows unknown input, requiring extra validation. | 1.3.6 | 6.09M | JIT | Code snippet(Commented code is not benchmarked) | 4 μs | Code snippet(Commented code is not benchmarked) | 4 μs | ||
zod | 4.4.3 | 245.64M | JIT | Code snippet | 170 ns | Code snippet | 208 ns | |||
zod/mini | 4.4.3 | 245.64M | JIT | Code snippet | 166 ns | Code snippet | 205 ns | |||