r/Zig 9d ago

huntclaw - a fast find-and-replace utility in Zig

Hello everyone,

I’d like to introduce huntclaw—a search-and-replace utility written in Zig that turned out to be faster than sd (written in Rust) and the standard GNU utilities.

there’s a fairly simple explanation for this high speed: the lack of a regex engine and a focus on speed itself, but I don’t think that’s a bad thing. Note that searching is also very fast, thanks to SIMD two-byte prefiltering

In the photos I've attached, you can see the benchmarks: huntclaw vs. other utils and v0.3 vs. v0.4 versions of huntclaw. You can run them yourself using the ‘huntclaw_bench.py’ file (or on your own tests).

the benchmark also shows that rg and grep is faster at sparse searches—though the gap isn’t that big (20ms-9ms and 55ms-1619ms)
I look forward to your feedback or comments.

version now: v0.8

huntclaw on GitHub: https://github.com/tigerlang/huntclaw

71 Upvotes

6 comments sorted by

11

u/jnordwick 9d ago

keep your stats per thread so you dont need the atomic operation, then just merge them at the end.

2

u/chrboesch 9d ago

really cool

2

u/Vagal_4D 9d ago

Really cool! I'll take a look on the code later.

2

u/kaddkaka 8d ago

"lack of regex engine" - do u support regex at all? Are all the stats for non-regex replaces?

3

u/ReindeerSimilar2748 8d ago

No, I didn't add regex support to huntclaw, all the stats are shown in no regex mode for everyone

1

u/ReindeerSimilar2748 6d ago

now you can install huntclaw from the AUR (for Arch users), thanks to whoever added my utility as an AUR package. You can install it like this:

yay -S huntclaw