Created
July 3, 2023 03:21
-
-
Save vigna/e8b2bf6b09c194d5c6c414647a140782 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use rand::rngs::SmallRng; | |
use rand::rngs::StdRng; | |
use rand::Rng; | |
use rand::SeedableRng; | |
use rand_chacha::ChaCha8Rng; | |
use std::hint::black_box; | |
use std::time::Instant; | |
fn main() { | |
const N: usize = 1024 * 1024 * 1024; | |
let mut data = Vec::<u64>::new(); | |
data.resize(N, 0); | |
let fill = data.as_mut_slice(); | |
let mut r = StdRng::seed_from_u64(0); | |
let start = Instant::now(); | |
black_box(r.fill(fill)); | |
println!("ChaCha12 {}", start.elapsed().as_nanos() as f64 / N as f64); | |
let mut r = ChaCha8Rng::seed_from_u64(0); | |
let start = Instant::now(); | |
black_box(r.fill(fill)); | |
println!("ChaCha8 {}", start.elapsed().as_nanos() as f64 / N as f64); | |
let mut r = SmallRng::seed_from_u64(0); | |
let start = Instant::now(); | |
black_box(r.fill(fill)); | |
println!( | |
"xoshiro256++ {}", | |
start.elapsed().as_nanos() as f64 / N as f64 | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment