Crates.io | bs64 |
lib.rs | bs64 |
version | 0.1.2 |
source | src |
created_at | 2023-10-15 18:11:33.577701 |
updated_at | 2023-10-16 13:25:51.649652 |
description | SIMD-accelerated Base64 encoding and decoding library |
homepage | |
repository | https://github.com/ozgb/bs64 |
max_upload_size | |
id | 1004050 |
size | 59,818 |
โจ SIMD-accelerated Base64 for Rust โจ
cargo add bs64
use bs64;
fn main() {
// Encode
let input = vec![2, 3, 4, 5];
let output: String = bs64::encode(&input);
// Decode
let decoded_output = bs64::decode(output.as_bytes());
}
Ran using 100k inputs, 10000 iterations on an Intelยฎ Coreโข i7-1065G7. Comparisons are made against base64 and data-encoding crates.
cargo run --features "cli" --release -- -b 100000 -i 10000
name | MB/s |
---|---|
๐ bs64::encode() | 4813.70 |
๐ bs64::encode_mut() | 6579.17 |
๐ bs64 fallback | 944.18 |
data_encoding | 858.51 |
data_encoding mut | 873.28 |
base64 | 748.02 |
base64 mut | 870.99 |
name | MB/s |
---|---|
๐ bs64::decode() | 3899.26 |
๐ bs64::decode_mut() | 3965.25 |
๐ bs64 fallback | 837.17 |
data_encoding | 647.33 |
data_encoding mut | 684.01 |
base64 | 761.68 |
base64 mut | 805.60 |
Code was initially ported from https://github.com/lemire/fastbase64
The simple
fallback implementation is based on the chromium
implementation from the fastbase64 repo. The use of iterators and chunking the input in the Rust implementation makes it easy for the compiler to vectorise the processing.
The AVX2 implementation is largely untouched compared with the original fastbase64
implementation.
The code is optimised for x86_64, and therefore assumes large-ish caches are available for storing lookup tables. I created a naive implementation that indexed a static array of valid base64 chars - the performance there was only slightly worse than the chromium LUT implementation, so I may add this as an option for low-memory targets (i.e. embedded).
Useful links: