Skip to content

Commit

Permalink
Use mask in gen_range_i benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
pitdicker authored and dhardy committed Mar 21, 2018
1 parent 9b6c387 commit 00ebb7b
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions benches/distributions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ distr_int!(distr_poisson, u64, Poisson::new(4.0));

// construct and sample from a range
macro_rules! gen_range_int {
($fnn:ident, $ty:ty, $low:expr, $high:expr, $incr:expr) => {
($fnn:ident, $ty:ident, $low:expr, $high:expr) => {
#[bench]
fn $fnn(b: &mut Bencher) {
let mut rng = XorShiftRng::new();
Expand All @@ -118,7 +118,8 @@ macro_rules! gen_range_int {
let mut accum: $ty = 0;
for _ in 0..::RAND_BENCH_N {
accum = accum.wrapping_add(rng.gen_range($low, high));
high += $incr; // force recalculation of range each time
// force recalculation of range each time
high = high.wrapping_add(1) & std::$ty::MAX;
}
black_box(accum);
});
Expand All @@ -127,9 +128,9 @@ macro_rules! gen_range_int {
}
}

gen_range_int!(gen_range_i8, i8, 20i8, 100, 0);
gen_range_int!(gen_range_i16, i16, -500i16, 2000, 1);
gen_range_int!(gen_range_i32, i32, -200_000_000i32, 800_000_000, 3);
gen_range_int!(gen_range_i64, i64, 3i64, 12345678901234, 3);
gen_range_int!(gen_range_i8, i8, -20i8, 100);
gen_range_int!(gen_range_i16, i16, -500i16, 2000);
gen_range_int!(gen_range_i32, i32, -200_000_000i32, 800_000_000);
gen_range_int!(gen_range_i64, i64, 3i64, 12345678901234);
#[cfg(feature = "i128_support")]
gen_range_int!(gen_range_i128, i128, -12345678901234i128, 12345678901234567890, 3);
gen_range_int!(gen_range_i128, i128, -12345678901234i128, 12345678901234567890);

0 comments on commit 00ebb7b

Please sign in to comment.