LogoLogo

Schema Benchmarks

    • home
      Home

    • download_2
      Download

    • timer
      Initialization
    • check_circle
      Validation
    • output_circle
      Parsing
    • swap_horiz
      Codec
    • schema
      Standard Schema
    • format_quote
      String

    • error
      Stack
    • assignment_turned_in
      TypeScript

  • JSON Schema

    • data_object
      Schema to JSON
    • code
      JSON to Schema
    • verified
      Compliance

    • deployed_code
      Libraries

    • article
      Blog
Expand sidebarExpand sidebar
Benchmarks/CodecCodec
github
GitHubGitHub
DiscordDiscord
PreferencesPreferences

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 clipboardCopy to clipboard
import * 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
Copy to clipboardCopy to clipboard
import * 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
format_quoteInvalid 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
  • flash_offNone
  • codeJIT
  • buildPrecompiled
LibrarysortVersiondownload/wksortOptimizationsEncodearrow_upwardDecodesort
@mionjs/run-types0.20.0128Precompiled
Code snippetCode snippet
const encode = createPrepareForJsonFn<bigint>();
encode(data)

(Setup code is not benchmarked)

69 ns
Code snippetCode snippet
const decode = createRestoreFromJsonFn<bigint>();
decode(data)

(Setup code is not benchmarked)

113 ns
sury11.1.0641.24KJIT
Code snippetCode snippet
const encode = S.encodeOrThrow(S.bigint, S.string);
encode(data)

(Setup code is not benchmarked)

69 ns
Code snippetCode snippet
const decode = S.decodeOrThrow(S.string, S.bigint);
decode(data)

(Setup code is not benchmarked)

79 ns
io-ts2.2.223.83MNone
Code snippetCode snippet
const BigIntFromString = new t.Type<bigint, string, string>(name, is, validate, encode);
BigIntFromString.encode(data)

(Setup code is not benchmarked)

71 ns
Code snippetCode snippet
const BigIntFromString = new t.Type<bigint, string, string>(name, is, validate, encode);
BigIntFromString.decode(data)

(Setup code is not benchmarked)

79 ns
zod/mini4.6.7470.6MJIT
Code snippetCode snippet
z.encode(codec, data)
99 ns
Code snippetCode snippet
z.decode(codec, data)
127 ns
zod4.6.7470.6MJIT
Code snippetCode snippet
z.codec(in_, out, { decode, encode }).encode(data)
104 ns
Code snippetCode snippet
z.codec(in_, out, { decode, encode }).decode(data)
113 ns
zod/mini (compile)4.6.7470.6MJIT
Code snippetCode snippet
z.encode(compiledCodec, data)
104 ns
Code snippetCode snippet
z.decode(compiledCodec, data)
134 ns
zod (compile)4.6.7470.6MJIT
Code snippetCode snippet
const compiledCodec = z.compile(codec, { strict: true });
compiledCodec.encode(data)

(Setup code is not benchmarked)

104 ns
Code snippetCode snippet
const compiledCodec = z.compile(codec, { strict: true });
compiledCodec.decode(data)

(Setup code is not benchmarked)

116 ns
effect (unknown)
Accepts unknown valuesAccepts unknown values
This codec allows unknown input, requiring extra validation.
4.1.566.63MNone
Code snippetCode snippet
Schema.encodeUnknownSync(Schema.BigIntFromString)(data)
220 ns
Code snippetCode snippet
Schema.decodeUnknownSync(Schema.BigIntFromString)(data)
281 ns
effect4.1.566.63MNone
Code snippetCode snippet
Schema.encodeSync(Schema.BigIntFromString)(data)
221 ns
Code snippetCode snippet
Schema.decodeSync(Schema.BigIntFromString)(data)
307 ns
typebox
Accepts unknown valuesAccepts unknown values
This codec allows unknown input, requiring extra validation.
1.4.716.74MJIT
Code snippetCode snippet
const BigIntFromString = Type.Codec(type).Decode(callback).Encode(callback);
Value.Encode(BigIntFromString, data)

(Setup code is not benchmarked)

4 μs
Code snippetCode snippet
const BigIntFromString = Type.Codec(type).Decode(callback).Encode(callback);
Value.Decode(BigIntFromString, data)

(Setup code is not benchmarked)

5 μs
Created by eskimojo for Open Circle

Preferences

Style
Theme
NPM browser
Code ligatures