No description
Find a file
2025-04-18 11:40:34 +05:30
examples add: base64: implement decodeSeq 2025-04-17 20:38:42 +05:30
src fix: base64: don't read past buffer 2025-04-18 11:40:11 +05:30
tests fix: base64: don't read past buffer 2025-04-18 11:40:11 +05:30
.gitignore (feat) initial commit 2024-09-11 17:12:32 +05:30
nim.cfg (feat) initial commit 2024-09-11 17:12:32 +05:30
README.md (xxx) update README.md 2024-09-13 12:19:01 +05:30
shell.nix (add) Nix shell 2024-09-12 15:24:08 +05:30
simdutf.nimble bump: 6.5.1 -> 6.5.12 2025-04-18 11:40:34 +05:30

High-level wrapper over simdutf

This package provides a nice little interface over simdutf, a fast, cross-architecture SIMD accelerated library for base64 encoding and decoding alongside encoding validation and conversion.

The low level bindings are present in simdutf/bindings, but do not use them unless you know what you're doing. The high level wrapper is memory safe* as it validates all allocations to be of the correct sizes to prevent buffer overflows.

How fast is it?

Here's a benchmark to show that. (Run this for yourselves with nimble benchmark)

Device: Laptop
CPU: AMD Ryzen 5 5600H @ 4.20Ghz with 12 cores
RAM: 16 GB of DDR4 @ 3200 MT/s + 24GB of swap (not used in this benchmark)

$ nimble benchmark
> generating sentences ...
> sentences generated; may the most optimized win
   min time    avg time  std dv   runs name
   0.337 ms    0.373 ms  ±0.016  x1000 encode 1000 strings (simdutf)
   2.741 ms    2.825 ms  ±0.039  x1000 encode 1000 strings (std/base64)

Real-World Usage

  • bali, a JavaScript engine written in Nim

This will hopefully soon fully replace std/base64 from the entirity of the Ferus' web engine's stack.

Usage (Base64)

The API is almost the same as std/base64.

import simdutf/base64

for i, name in [
    "Joseph",
    "Andreas",
    "James",
    "Thomas",
    "Monika",
    "Prateek",
    "Ahmad",
    "Anton",
]:
  echo name.encode(urlSafe = (i mod 2) == 0) # We support URL safe encoding too

Usage (Unicode)

The unicode wrapper is still very much a work-in-progress. Most of the functions in the unicode module aren't wrapped yet. Feel free to send PRs, though :)

import simdutf/unicode

assert validateUtf8("Hello simdutf!")
assert validateAscii("This is ascii, isn't it?")
assert validateUtf16("你好,世界")
assert validateUtf32("")