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 | /wk | Optimizations | Encode | Decode | |||||
|---|---|---|---|---|---|---|---|---|---|---|
sury | 11.0.0-rc.1 | n/a | JIT | Code snippet(Commented code is not benchmarked) | 91 ns | Code snippet(Commented code is not benchmarked) | 114 ns | |||
zod/mini | 4.4.3 | n/a | JIT | Code snippet | 177 ns | Code snippet | 222 ns | |||
zod | 4.4.3 | n/a | JIT | Code snippet | 189 ns | Code snippet | 200 ns | |||
typebox | Accepts unknown valuesThis codec allows unknown input, requiring extra validation. | 1.3.15 | n/a | JIT | Code snippet(Commented code is not benchmarked) | 4 μs | Code snippet(Commented code is not benchmarked) | 4 μs | ||