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.string(), z.bigint(), { decode: (str) => BigInt(str), encode: (bigint) => bigint.toString(), }); 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 | |||||
|---|---|---|---|---|---|---|---|---|---|---|
typebox | Accepts unknown valuesThis codec allows unknown input, requiring extra validation. | 1.3.8 | n/a | JIT | Code snippet(Commented code is not benchmarked) | 5 μs | Code snippet(Commented code is not benchmarked) | 5 μs | ||
effect@beta (unknown) | Accepts unknown valuesThis codec allows unknown input, requiring extra validation. | 4.0.0-beta.101 | n/a | None | Code snippet | 2 μs | Code snippet | 2 μs | ||
effect@beta | 4.0.0-beta.101 | n/a | None | Code snippet | 2 μs | Code snippet | 2 μs | |||
effect | 3.22.0 | n/a | None | Code snippet | 382 ns | Code snippet | 439 ns | |||
effect (unknown) | Accepts unknown valuesThis codec allows unknown input, requiring extra validation. | 3.22.0 | n/a | None | Code snippet | 377 ns | Code snippet | 447 ns | ||
zod/mini | 4.4.3 | n/a | JIT | Code snippet | 191 ns | Code snippet | 226 ns | |||
zod | 4.4.3 | n/a | JIT | Code snippet | 184 ns | Code snippet | 233 ns | |||
sury | 11.0.0-alpha.11 | n/a | JIT | Code snippet(Commented code is not benchmarked) | 83 ns | Code snippet(Commented code is not benchmarked) | 114 ns | |||
io-ts | 2.2.22 | n/a | None | Code snippet(Commented code is not benchmarked) | 82 ns | Code snippet(Commented code is not benchmarked) | 119 ns | |||