Skip to content

Commit

Permalink
Split gen_usize_* benchmarks into gen_u32_* and gen_u64_*
Browse files Browse the repository at this point in the history
Copy non-controversial part of #36
Credit: Paul Dicker <pitdicker@gmail.com>
  • Loading branch information
dhardy committed Nov 10, 2017
1 parent fdb09d4 commit d387570
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions benches/generators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const BYTES_LEN: usize = 1024;
use std::mem::size_of;
use test::{black_box, Bencher};

use rand::{Rng, NewSeeded, SeedFromRng, StdRng, OsRng, Rand, Default};
use rand::{Rng, NewSeeded, Sample, SeedFromRng, StdRng, OsRng};
use rand::prng::{XorShiftRng, IsaacRng, Isaac64Rng, ChaChaRng};

macro_rules! gen_bytes {
Expand Down Expand Up @@ -37,27 +37,34 @@ gen_bytes!(gen_bytes_std, StdRng);
gen_bytes!(gen_bytes_os, OsRng);


macro_rules! gen_usize {
($fnn:ident, $gen:ident) => {
macro_rules! gen_uint {
($fnn:ident, $ty:ty, $gen:ident) => {
#[bench]
fn $fnn(b: &mut Bencher) {
let mut rng = $gen::new().unwrap();
b.iter(|| {
for _ in 0..RAND_BENCH_N {
black_box(usize::rand(&mut rng, Default));
black_box(rng.gen::<$ty>());
}
});
b.bytes = size_of::<usize>() as u64 * RAND_BENCH_N;
b.bytes = size_of::<$ty>() as u64 * RAND_BENCH_N;
}
}
}

gen_usize!(gen_usize_xorshift, XorShiftRng);
gen_usize!(gen_usize_isaac, IsaacRng);
gen_usize!(gen_usize_isaac64, Isaac64Rng);
gen_usize!(gen_usize_chacha, ChaChaRng);
gen_usize!(gen_usize_std, StdRng);
gen_usize!(gen_usize_os, OsRng);
gen_uint!(gen_u32_xorshift, u32, XorShiftRng);
gen_uint!(gen_u32_isaac, u32, IsaacRng);
gen_uint!(gen_u32_isaac64, u32, Isaac64Rng);
gen_uint!(gen_u32_chacha, u32, ChaChaRng);
gen_uint!(gen_u32_std, u32, StdRng);
gen_uint!(gen_u32_os, u32, OsRng);

gen_uint!(gen_u64_xorshift, u64, XorShiftRng);
gen_uint!(gen_u64_isaac, u64, IsaacRng);
gen_uint!(gen_u64_isaac64, u64, Isaac64Rng);
gen_uint!(gen_u64_chacha, u64, ChaChaRng);
gen_uint!(gen_u64_std, u64, StdRng);
gen_uint!(gen_u64_os, u64, OsRng);

macro_rules! init_gen {
($fnn:ident, $gen:ident) => {
Expand Down

0 comments on commit d387570

Please sign in to comment.