Skip to content

Commit 5f2686a

Browse files
committed
Add benchmarks for ReseedingRng
1 parent 8c500a4 commit 5f2686a

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

benches/generators.rs

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ const BYTES_LEN: usize = 1024;
99
use std::mem::size_of;
1010
use test::{black_box, Bencher};
1111

12-
use rand::{Rng, NewRng, StdRng, OsRng, JitterRng};
12+
use rand::{Rng, NewRng, StdRng, OsRng, JitterRng, EntropyRng};
1313
use rand::{XorShiftRng, Hc128Rng, IsaacRng, Isaac64Rng, ChaChaRng};
14+
use rand::reseeding::ReseedingRng;
1415

1516
macro_rules! gen_bytes {
1617
($fnn:ident, $gen:ident) => {
@@ -162,3 +163,39 @@ macro_rules! chacha_rounds {
162163
chacha_rounds!(gen_bytes_chacha8, gen_u32_chacha8, gen_u64_chacha8, 8);
163164
chacha_rounds!(gen_bytes_chacha12, gen_u32_chacha12, gen_u64_chacha12, 12);
164165
chacha_rounds!(gen_bytes_chacha20, gen_u32_chacha20, gen_u64_chacha20, 20);
166+
167+
168+
#[bench]
169+
fn reseeding_hc128_bytes(b: &mut Bencher) {
170+
let mut rng = ReseedingRng::new(Hc128Rng::new().unwrap(),
171+
128*1024*1024,
172+
EntropyRng::new());
173+
let mut buf = [0u8; BYTES_LEN];
174+
b.iter(|| {
175+
for _ in 0..RAND_BENCH_N {
176+
rng.fill_bytes(&mut buf);
177+
black_box(buf);
178+
}
179+
});
180+
b.bytes = BYTES_LEN as u64 * RAND_BENCH_N;
181+
}
182+
183+
macro_rules! reseeding_uint {
184+
($fnn:ident, $ty:ty) => {
185+
#[bench]
186+
fn $fnn(b: &mut Bencher) {
187+
let mut rng = ReseedingRng::new(Hc128Rng::new().unwrap(),
188+
128*1024*1024,
189+
EntropyRng::new());
190+
b.iter(|| {
191+
for _ in 0..RAND_BENCH_N {
192+
black_box(rng.gen::<$ty>());
193+
}
194+
});
195+
b.bytes = size_of::<$ty>() as u64 * RAND_BENCH_N;
196+
}
197+
}
198+
}
199+
200+
reseeding_uint!(reseeding_hc128_u32, u32);
201+
reseeding_uint!(reseeding_hc128_u64, u64);

0 commit comments

Comments
 (0)