Skip to content

Commit 11c6178

Browse files
committed
Add thread_rng benchmarks
1 parent f7a1038 commit 11c6178

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

benches/generators.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use test::{black_box, Bencher};
1212
use rand::{RngCore, Rng, SeedableRng, NewRng, StdRng, OsRng, JitterRng, EntropyRng};
1313
use rand::{XorShiftRng, Hc128Rng, IsaacRng, Isaac64Rng, ChaChaRng};
1414
use rand::reseeding::ReseedingRng;
15+
use rand::thread_rng;
1516

1617
macro_rules! gen_bytes {
1718
($fnn:ident, $gen:ident) => {
@@ -184,3 +185,22 @@ macro_rules! reseeding_uint {
184185

185186
reseeding_uint!(reseeding_hc128_u32, u32);
186187
reseeding_uint!(reseeding_hc128_u64, u64);
188+
189+
190+
macro_rules! threadrng_uint {
191+
($fnn:ident, $ty:ty) => {
192+
#[bench]
193+
fn $fnn(b: &mut Bencher) {
194+
let mut rng = thread_rng();
195+
b.iter(|| {
196+
for _ in 0..RAND_BENCH_N {
197+
black_box(rng.gen::<$ty>());
198+
}
199+
});
200+
b.bytes = size_of::<$ty>() as u64 * RAND_BENCH_N;
201+
}
202+
}
203+
}
204+
205+
threadrng_uint!(thread_rng_u32, u32);
206+
threadrng_uint!(thread_rng_u64, u64);

0 commit comments

Comments
 (0)