b64/README.md

98 lines
2.1 KiB
Markdown
Raw Permalink Normal View History

# b64
2023-08-30 22:50:50 +02:00
A tool I created to
* Base64 encode/decode text quickly from [helix](https://helix-editor.com/) :)
* Learn a bit of Zig
## Usage
```
Usage: b64 [-e] [-d] <string>
-h, --help
Display this help and exit.
2023-10-29 16:36:26 +01:00
-b, --benchmark
Benchmark b64
-d, --decode
Decode base64 to string.
-e, --encode
Encode string to base64.
-v, --version
Display version.
<str>
String to encode or decode.
```
### Encoding
```shell
$ b64 -e "encode this string to base64"
ZW5jb2RlIHRoaXMgc3RyaW5nIHRvIGJhc2U2NA==
# From stdin
$ echo -n "encode this string to base64" | b64 -e
ZW5jb2RlIHRoaXMgc3RyaW5nIHRvIGJhc2U2NA==
$
```
### Decoding
```shell
$ b64 -d ZW5jb2RlIHRoaXMgc3RyaW5nIHRvIGJhc2U2NA==
encode this string to base64
# From stdin
$ echo -n "ZW5jb2RlIHRoaXMgc3RyaW5nIHRvIGJhc2U2NA==" | b64 -d
encode this string to base64
$
```
2023-10-29 16:36:26 +01:00
### Benchmark
```shell
zig build
./zig-out/bin/b64 -b
encode
280335 iterations 12401.51ns per iterations
40 bytes per iteration
worst: 138209ns median: 10042ns stddev: 318640155486692400.00ns
decode
282250 iterations 12048.95ns per iterations
28 bytes per iteration
worst: 76416ns median: 10125ns stddev: 318604539142680300.00ns
zig build -Doptimize=ReleaseSafe
./zig-out/bin/b64 -b
encode
1284225 iterations 1228755.55ns per iterations
40 bytes per iteration
worst: 0ns median: 416ns stddev: 86582387.80ns
decode
2295809 iterations 1226658.46ns per iterations
28 bytes per iteration
worst: 0ns median: 375ns stddev: 86582411.15ns
zig build -Doptimize=ReleaseFast
./zig-out/bin/b64 -b
encode
1355137 iterations 93007.39ns per iterations
40 bytes per iteration
worst: 526709ns median: 83ns stddev: 37608456664387784.00ns
decode
2729217 iterations 105389.71ns per iterations
28 bytes per iteration
worst: 535583ns median: 83ns stddev: 36170163385699460.00ns
```
## Build
```shell
$ git clone https://git.kcbark.net/zig/b64.git && cd b64
$ zig build -Doptimize=ReleaseFast
$ cp zig-out/bin/b64 ~/.local/bin
2023-10-29 16:36:26 +01:00
```