Crypto benchmarks: Zig vs Rust performance comparison.
Cryptographic performance benchmarks across Zig stdlib and Rust implementations with hardware acceleration.
Supported platforms: Linux and macOS (x86_64, aarch64)
-
SHA-256: Secure Hash Algorithm 256-bit
- Zig:
std.crypto.hash.sha2.Sha256 - Rust:
sha2crate with hardware acceleration
- Zig:
-
SHA-512: Secure Hash Algorithm 512-bit
- Zig:
std.crypto.hash.sha2.Sha512* - Rust:
sha2crate with hardware acceleration
* Zig's SHA-512 currently lacks hardware acceleration (#22266), resulting in expected performance differences.
- Zig:
Run benchmarks to generate timestamped results in results/ directory:
zig build bench -- --save-results- Zig 0.14.1 or later
- Rust toolchain (for building the comparison library)
git clone https://github.com/yourusername/zig-crypto-bench
cd zig-crypto-bench
zig build bench# Run all benchmarks with default settings (500 iterations, 50 warmup)
zig build bench
# Save timestamped results to results/ directory for contribution
zig build bench -- --save-results
# Run with custom iteration counts
zig build bench -- --iterations 2000 --warmup 200
# Generate JSON output for analysis
zig build bench -- --json > results.json
# Filter specific tests by size
zig build bench -- --filter 1MB
# Combined: save results with custom settings
zig build bench -- --save-results --iterations 1000 --warmup 100- Adaptive iteration counts with auto-scaling for large inputs
- Warmup phase to stabilize CPU performance
- Auto-batching for accurate timing of fast operations
- Correctness verification via bitwise output comparison
- Transparent build configuration and optimization flags
- Statistical analysis
- CPU frequency governor detection and throttling warnings
- Framework versioning with git commit tracking in results
- Two measurement modes: FFI (both use C ABI for fair comparison, default) and native (Zig direct/Rust FFI)
Hardware Results: Help expand hardware coverage by contributing benchmark results from your system. Run with --save-results and submit the generated markdown files from the results/ directory.
Open Issues: Check the issues for tasks ranging from small improvements to major features.
Development Conventions:
- Test functions must print their title at the start using
std.debug.print("\n✓ Running: Test Name\n", .{});(This is idiomatic in Zig as the test runner lacks built-in verbose output)