Crate codex_percent

Source
Expand description

§codex-percent

Discord chat Crates.io Docs License License MSRV

meme again asking you to reduce re-allocations

no_std friendly percent en-de-coding for the 1%

§Usage

§Fixed Array

This uses fixed bytearray as output where you are responsible of ensuring large enough output size.

With FixedEncoder

cargo add codex-percent --no-default-features --features fixed,encoder

With FixedDecoder

cargo add codex-percent --no-default-features --features fixed,decoder

§Allocating Vec

This uses allocating vec as output where you provide a mutable Vec that will re-allocate if needed.

With VecEncoder (uses alloc::vec)

cargo add codex-percent --no-default-features --features vec,encoder

With VecDecoder (uses alloc::vec)

cargo add codex-percent --no-default-features --features vec,decoder

See examples.

§Decoder Benchmarks

In MacBook 13“ M1 comparitative results:

TypeScenarioPerf
FixedDecoderPoop-U1-4B[16.897 ns 16.928 ns 16.969 ns]
FixedDecoderPoop-U3-12B[38.939 ns 39.021 ns 39.113 ns]
FixedDecoderPoop-U6-24B[73.677 ns 73.746 ns 73.830 ns]
VecDecoderPoop-U6-24B straightline[149.90 ns 151.21 ns 152.46 ns]
VecDecoderPoop-U6-24B capped, re-use[83.460 ns 83.646 ns 83.889 ns]

§Encoder Benchmarks

In MacBook 13“ M1 comparitative results:

TypeScenarioPerf
FixedEncoderPoop-U1-3B >> 12B[8.7721 ns 8.7840 ns 8.7991 ns]
FixedEncoderPoop-U3-9B >> 36B[18.073 ns 18.149 ns 18.228 ns]
FixedEncoderPoop-U6-18B >> 72B[29.173 ns 29.267 ns 29.375 ns]
VecEncoderno-init-cap Poop-U1-3B >> 12B[42.965 ns 43.090 ns 43.221 ns]
VecEncoderno-init-cap Poop-U3-9B >> 36B[112.44 ns 112.84 ns 113.36 ns]
VecEncoderno-init-cap Poop-U6-18B >> 72B[153.92 ns 154.25 ns 154.59 ns]
VecEncodercapped Poop-U1-3B >> 12B[24.478 ns 24.507 ns 24.535 ns]
VecEncodercapped Poop-U3-9B >> 36B[37.446 ns 37.578 ns 37.724 ns]
VecEncodercapped Poop-U6-18B >> 72B[52.808 ns 52.976 ns 53.167 ns]
VecEncoderre-use Poop-U1-3B >> 12B[12.565 ns 12.605 ns 12.649 ns]
VecEncoderre-use Poop-U3-9B >> 36B[21.859 ns 21.906 ns 21.957 ns]
VecEncoderre-use Poop-U6-18B >> 72B[37.303 ns 37.371 ns 37.445 ns]

If you know the output size and can deal with a potential panic out-of-bounds, FixedEncoder is fast.

Panic free VecEncoder capped means Vec::with_capacity() and re-use if needed e.g. with .clear()

If you have large output, use VecEncoder as arrays are more suitable for small outputs.

Structs§

Enums§