GithubHelp home page GithubHelp logo

bs64's Introduction

๐Ÿš€ Base 64

Docs

โœจ SIMD-accelerated Base64 for Rust โœจ

๐ŸŒŸ Features

  • ๐Ÿ’ก Uses AVX2 instructions for super-fast encoding and decoding
  • ๐Ÿ”„ Fallback when AVX2 is unavailable uses any available SIMD

๐ŸŽฏ Project goals

  • ๐Ÿ”ง Simple, idiomatic API
  • ๐Ÿ“ฆ Sensible defaults
  • โšก Fast

Installation

cargo add bs64

Usage

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());
}

Benchmarks

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

Encode

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

Decode

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

Implementation Details

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:

TODO

  • Integration tests
  • Benchmarking suite
  • Comply with MIME, UTF-7, and other Base64 standards
  • Regression tests + benchmark in Github Actions
  • Change default implementation with feature flags
  • Builders for custom configs at runtime

bs64's People

Contributors

ozgb avatar metal-joker avatar

Stargazers

 avatar  avatar Hector avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.