Crates.io | five8 |
lib.rs | five8 |
version | 0.2.1 |
source | src |
created_at | 2024-07-29 20:13:34.872888 |
updated_at | 2024-10-13 11:15:22.013832 |
description | Fast base58 encoding and decoding for 32-byte and 64-byte arrays. |
homepage | https://github.com/kevinheavey/five8 |
repository | https://github.com/kevinheavey/five8 |
max_upload_size | |
id | 1319178 |
size | 80,829 |
five8
provides fast base58 encoding and decoding for 32-byte and 64-byte arrays.
It is a Rust port of fd_base58.
There are four functions in the public api:
encode_32
encode_64
decode_32
decode_64
let mut buf = [0u8; 44];
let bytes = &[
24, 243, 6, 223, 230, 153, 210, 8, 92, 137, 123, 67, 164, 197, 79, 196, 125, 43, 183, 85,
103, 91, 232, 167, 73, 131, 104, 131, 0, 101, 214, 231,
];
let len = five8::encode_32(bytes, &mut buf);
assert_eq!(
&buf[..len as usize],
[
50, 103, 80, 105, 104, 85, 84, 106, 116, 51, 70, 74, 113, 102, 49, 86, 112, 105,
100, 103, 114, 89, 53, 99, 90, 54, 80, 117, 121, 77, 99, 99, 71, 86, 119, 81, 72,
82, 102, 106, 77, 80, 90, 71
]
);
assert_eq!(len, 44);
fn example_decode_32() {
let bytes = b"2gPihUTjt3FJqf1VpidgrY5cZ6PuyMccGVwQHRfjMPZG";
let mut out = [0u8; 32];
five8::decode_32(bytes, &mut out).unwrap();
assert_eq!(
out,
[
24, 243, 6, 223, 230, 153, 210, 8, 92, 137, 123, 67, 164, 197, 79, 196, 125, 43,
183, 85, 103, 91, 232, 167, 73, 131, 104, 131, 0, 101, 214, 231
]
);
}
These benchmarks were run on a laptop with AVX2 support. If your machine does not support AVX2 instructions it will be slower but should still be faster than the alternatives - see the second set of benchmarks where AVX2 is disabled.
RUSTFLAGS='-C target-cpu-native
)Benchmark | five8 | Lou-Kamades/fd_bs58 | bs58-rs |
---|---|---|---|
decode_32 | 36 ns | 88 ns | 291 ns |
decode_64 | 124 ns | 203 ns | 1092 ns |
encode_32 | 55 ns | 96 ns | 682 ns |
encode_64 | 102 ns | 209 ns | 2781 ns |
RUSTFLAGS
)Benchmark | five8 | Lou-Kamades/fd_bs58 | bs58-rs |
---|---|---|---|
decode_32 | 49 ns | 107 ns | 320 ns |
decode_64 | 162 ns | 246 ns | 1176 ns |
encode_32 | 86 ns | 98 ns | 824 ns |
encode_64 | 179 ns | 219 ns | 3370 ns |
five8_const
: compile-time base58 decoding.