No description
Find a file
2024-06-09 12:14:35 +02:00
src fix: Styling 2024-03-31 14:53:39 +02:00
.gitignore fix: Update to zig 0.13.0 2024-06-09 12:14:35 +02:00
build.zig fix: Update to zig 0.13.0 2024-06-09 12:14:35 +02:00
build.zig.zon fix: Update to zig 0.13.0 2024-06-09 12:14:35 +02:00
README.md docs: Add benchmark 2023-10-29 16:36:26 +01:00

b64

A tool I created to

  • Base64 encode/decode text quickly from helix :)
  • Learn a bit of Zig

Usage

Usage: b64 [-e] [-d] <string>
    -h, --help
            Display this help and exit.

    -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

$ b64 -e "encode this string to base64"
ZW5jb2RlIHRoaXMgc3RyaW5nIHRvIGJhc2U2NA==

# From stdin
$ echo -n "encode this string to base64" | b64 -e
ZW5jb2RlIHRoaXMgc3RyaW5nIHRvIGJhc2U2NA==
$

Decoding

$ b64 -d ZW5jb2RlIHRoaXMgc3RyaW5nIHRvIGJhc2U2NA==
encode this string to base64

# From stdin
$ echo -n "ZW5jb2RlIHRoaXMgc3RyaW5nIHRvIGJhc2U2NA==" | b64 -d
encode this string to base64
$

Benchmark

 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

$ git clone https://git.kcbark.net/zig/b64.git && cd b64
$ zig build -Doptimize=ReleaseFast
$ cp zig-out/bin/b64 ~/.local/bin