jadnohra / jadnohra/zig-crypto-bench

Investigate why Rust outperforms Zig by 40% on 32B inputs

Open
#2 1 comment 0 reactions 0 assignees View on GitHub
invalid
Dominant language
Zig
Stars
3
Forks
1
PR merge metrics
No merged PRs in 30d

Description

On most input sizes, Zig leads by ~10%, but on 32B inputs Rust is unexpectedly 40% faster. This anomaly needs investigation.

See benchmark results: [results/2025-09-13-23-49-36.md](https://github.com/jadnohra/zig-crypto-bench/blob/main/results/2025-09-13-23-49-36.md#sha256-32-b)

Results showing the anomaly:
- Zig stdlib: 42 ns/op (726.61 MB/s)
- Rust (sha2): 29 ns/op (1052.33 MB/s) - **1.45x faster**

Possible causes to investigate:
- FFI overhead differences (Rust called via FFI, Zig runs natively)
- Timer measurement noise at ~25-29ns durations
- Different startup/initialization overhead
- Branch prediction patterns
- Cache alignment effects

Need to determine if this is reproducible across different hardware or just measurement noise.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with results/2025-09-13-23-49-36.md and inspect the SHA-256 32B benchmark results. Reproduce the comparison across different hardware while checking the listed possibilities, including FFI overhead and timer noise. Done means determining whether the 40% Rust advantage is reproducible or measurement noise.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust, zig
Domain
cryptography, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.