A Rust project for benchmarking the performance of SHAKE, SHA2, and SHA3 hash functions across randomly generated inputs of various sizes.
This project provides comprehensive benchmarks for:
- SHA2-224
- SHA2-256
- SHA2-384
- SHA2-512
- SHA3-224
- SHA3-256
- SHA3-384
- SHA3-512
- SHAKE128
- SHAKE256
- Criterion-based benchmarks: Uses the Criterion library for statistical analysis and accurate performance measurements
- Multiple input sizes: Tests performance across different data sizes (1KB, 4KB, 16KB, 64KB, 256KB)
- Throughput analysis: Measures both execution time and throughput (MB/s)
- HTML reports: Generates detailed HTML reports with graphs and statistics
- Random data generation: Uses cryptographically secure random data for testing
- Rust 1.70 or later
- Cargo
To run all benchmarks:
cargo benchTo run benchmarks for specific hash functions:
# Run only SHA2 benchmarks
cargo bench "SHA2"
# Run only SHA3 benchmarks
cargo bench "SHA3"
# Run only SHAKE benchmarks
cargo bench "SHAKE"
# Run the comparison benchmark (all algorithms with 16KB data)
cargo bench "Hash Comparison"cargo runThis will run a quick demonstration showing the hash functions in action with sample data.
cargo testAfter running benchmarks, you can find detailed HTML reports in the target/criterion/ directory. Open target/criterion/report/index.html in your browser to view interactive performance charts.
The benchmarks measure:
- Execution time: How long each hash function takes
- Throughput: Data processed per second (MB/s)
- Statistical analysis: Mean, standard deviation, and confidence intervals
Generally, you can expect:
- SHA2 vs SHA3: SHA2 is typically faster than SHA3 due to hardware optimizations and simpler operations
- Hash size impact: Larger hash sizes (512-bit) may be slower than smaller ones (256-bit) for the same family
- SHAKE functions: Performance depends on the requested output length
- Input size scaling: Throughput often increases with larger input sizes due to amortized overhead
Hash Comparison/SHA2-256 time: [45.2 µs 45.8 µs 46.4 µs]
thrpt: [345.2 MB/s 350.1 MB/s 354.7 MB/s]
Hash Comparison/SHA3-256 time: [89.1 µs 90.2 µs 91.4 µs]
thrpt: [175.4 MB/s 177.8 MB/s 179.9 MB/s]
sha2: SHA2 family implementationsha3: SHA3 and SHAKE implementationcriterion: Benchmarking frameworkrand: Random data generationclap: Command line parsing (for future CLI features)
hash-compare/
├── src/
│ └── main.rs # Library functions and demo app
├── benches/
│ └── hash_benchmark.rs # Criterion benchmarks
├── Cargo.toml # Dependencies and configuration
└── README.md # This file
- Add the dependency to
Cargo.toml - Import the hash function in
src/main.rs - Create wrapper functions following the existing pattern
- Add benchmark functions in
benches/hash_benchmark.rs
You can modify the input sizes in benches/hash_benchmark.rs:
for size in [1024, 4096, 16384, 65536, 262144].iter() {
// Add or modify sizes here
}- Run benchmarks in release mode (automatically done with
cargo bench) - Close other applications to reduce system noise
- Run on consistent hardware for reproducible results
- Consider CPU frequency scaling and thermal throttling
- Fork the repository
- Create a feature branch
- Add your improvements
- Run tests and benchmarks
- Submit a pull request
This project is open source. Feel free to use, modify, and distribute.