Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dlesl/b64_nif
Fast base64 encoding and decoding for Erlang
https://github.com/dlesl/b64_nif
Last synced: 2 months ago
JSON representation
Fast base64 encoding and decoding for Erlang
- Host: GitHub
- URL: https://github.com/dlesl/b64_nif
- Owner: dlesl
- License: apache-2.0
- Created: 2022-01-16T18:17:55.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2022-10-31T21:47:07.000Z (about 2 years ago)
- Last Synced: 2024-10-08T15:19:01.360Z (3 months ago)
- Language: C
- Size: 116 KB
- Stars: 6
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
b64_nif
=====[![Hex pm](http://img.shields.io/hexpm/v/b64_nif.svg?style=flat)](https://hex.pm/packages/b64_nif)
Erlang's `base64` module is implemented in Erlang and rather slow. This library
provides a very fast alternative using [aklomp's
base64](https://github.com/aklomp/base64).There is another library, [b64fast](https://github.com/zuckschwerdt/b64fast),
which takes a similar approach. This library behaves slightly differently in that it:* Validates input while decoding (raises `bagarg`)
* Uses dirty schedulers for large inputs rather than a streaming approach
* Only supports Base64
* Is even faster thanks to [base64](https://github.com/aklomp/base64) (on my machine at least)Use
---Add it to your `rebar.config`, for example `{deps, [{b64_nif, "0.1.4"}]}.`
Use `b64_nif:encode/1` and `b64_nif:decode/1` as drop-in replacements for
`base64:encode/1` and `base64:decode/1`.Benchmarks
----------Run `./bench.sh`
```
== Testing with 100 B ==
fun base64:encode/1: 1000000 iterations in 3047 ms: 328191 it/sec
fun b64fast:encode64/1: 1000000 iterations in 935 ms: 1069518 it/sec
fun b64_nif:encode/1: 1000000 iterations in 298 ms: 3355704 it/sec
fun base64:decode/1: 1000000 iterations in 2951 ms: 338868 it/sec
fun b64fast:decode64/1: 1000000 iterations in 908 ms: 1101321 it/sec
fun b64_nif:decode/1: 1000000 iterations in 378 ms: 2645502 it/sec== Testing with 1 MB ==
fun base64:encode/1: 1000 iterations in 30087 ms: 33 it/sec
fun b64fast:encode64/1: 1000 iterations in 1096 ms: 912 it/sec
fun b64_nif:encode/1: 1000 iterations in 120 ms: 8333 it/sec
fun base64:decode/1: 1000 iterations in 28293 ms: 35 it/sec
fun b64fast:decode64/1: 1000 iterations in 969 ms: 1031 it/sec
fun b64_nif:decode/1: 1000 iterations in 133 ms: 7518 it/sec
```