All benchmarks run on x86_64 Linux with Rust 1.70+. Results from cargo bench --bench crypto_rng --features "crypto_rng custom_rng aes".
| RNG Implementation | next_u32 | next_u64 | Performance Rank |
|---|---|---|---|
| ChaCha20Rng | 6.66 ns | 13.01 ns | 🥇 Fastest |
| Blake3Drbg | 9.36 ns | 17.95 ns | 🥈 High Security |
| ChainSeedX | 9.81 ns | 18.78 ns | 🥉 Blockchain-Optimized |
| EntroCrypt | 15.75 ns | 29.05 ns | Maximum Security |
| AesCtrRng | - | - | AES-Based |
| RNG Implementation | fill_bytes_64 (ns) | fill_bytes_1024 (µs) | Throughput (MB/s) |
|---|---|---|---|
| ChaCha20Rng | 98.78 ns | 1.57 µs | ~654 MB/s |
| Blake3Drbg | 138.35 ns | 2.23 µs | ~457 MB/s |
| ChainSeedX | 165.19 ns | - | ~389 MB/s |
| EntroCrypt | 272.41 ns | - | ~235 MB/s |
| RNG | Throughput | Use Case |
|---|---|---|
| Xoshiro256+ | ~2.0 GB/s | Simulations, games |
| PCG64 | ~1.5 GB/s | General computing |
| Operation | ChaCha20Rng | Blake3Drbg | ChainSeedX | EntroCrypt |
|---|---|---|---|---|
| next_u32() | 6.66 | 9.36 | 9.81 | 15.75 |
| next_u64() | 13.01 | 17.95 | 18.78 | 29.05 |
| fill_bytes(64B) | 98.78 | 138.35 | 165.19 | 272.41 |
| fill_bytes(1KB) | 1,570 | 2,230 | - | - |
| RNG | State Size | Total Size | Security Level |
|---|---|---|---|
| Xoshiro256+ | 32 bytes | ~64 bytes | Fast (non-crypto) |
| PCG64 | 16 bytes | ~32 bytes | Fast (non-crypto) |
| ChaCha20Rng | 100 bytes | ~150 bytes | Cryptographically secure |
| Blake3Drbg | ~150 bytes | ~200 bytes | Cryptographically secure |
| AesCtrRng | ~180 bytes | ~230 bytes | Cryptographically secure |
| ChainSeed-X | ~200 bytes | ~300 bytes | Blockchain-aware |
| EntroCrypt | ~300 bytes | ~400 bytes | Maximum security |
- Use fast RNGs for bulk generation
- Cache RNG instances when possible
- Use SIMD features when available
- Prefer
fill_bytesfor large buffers
clock-rand performance vs rand crate (measured with comparison benchmarks):
- ChaCha20Rng: ~6.7x faster than
rand_chacha::ChaCha20Rngfornext_u32 - Xoshiro256+: ~1.5x faster than
rand_xoshiro::Xoshiro256Plus - PCG64: Competitive with
rand_pcg::Pcg64 - Crypto RNGs: Optimized for blockchain and security-critical applications
- Framework: Criterion.rs with 100 statistical samples per benchmark
- Platform: x86_64 Linux, Rust 1.70+
- Confidence: 95% statistical confidence intervals reported
- Outliers: Automatically detected and handled (1-9% across benchmarks)
- Operations: Single value generation (
next_u32/next_u64) and bulk operations (fill_bytes)
-
Choose the right RNG for your use case:
- Use fast RNGs (Xoshiro256+, PCG64) for simulations/games
- Use crypto RNGs (ChaCha20Rng, Blake3Drbg) for security applications
- Use specialized RNGs (ChainSeedX, EntroCrypt) for blockchain/consensus
-
Bulk operations are much faster:
// ❌ Slow: individual calls for _ in 0..1024 { let value = rng.next_u32(); } // ✅ Fast: bulk operations let mut buffer = [0u32; 1024]; rng.fill_bytes(buffer.as_mut_bytes()); // ~10-50x faster
-
Cache RNG instances:
// ✅ Create once, reuse let mut rng = ChaCha20Rng::new(&seed)?;
-
Enable appropriate features:
clock-rand = { version = "1.0", features = ["crypto_rng", "aes"] }