Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow sampling from a closed integer range #2

Merged
merged 4 commits into from
Oct 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions benches/distributions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,29 @@ fn distr_range_int(b: &mut Bencher) {
b.bytes = size_of::<i64>() as u64 * ::RAND_BENCH_N;
}

#[bench]
fn distr_range2_int(b: &mut Bencher) {
let mut rng = XorShiftRng::new().unwrap();
let distr = range2::Range::new(3i64, 134217671i64);
macro_rules! distr_range2_int {
($fnn:ident, $ty:ty, $low:expr, $high:expr) => {
#[bench]
fn $fnn(b: &mut Bencher) {
let mut rng = XorShiftRng::new().unwrap();
let distr = range2::Range::new($low, $high);

b.iter(|| {
for _ in 0..::RAND_BENCH_N {
black_box(distr.sample(&mut rng));
b.iter(|| {
for _ in 0..::RAND_BENCH_N {
let x: $ty = distr.sample(&mut rng);
black_box(x);
}
});
b.bytes = size_of::<$ty>() as u64 * ::RAND_BENCH_N;
}
});
b.bytes = size_of::<i64>() as u64 * ::RAND_BENCH_N;
}
}

distr_range2_int!(distr_range2_i8, i8, 20i8, 100);
distr_range2_int!(distr_range2_i16, i16, -500i16, 2000);
distr_range2_int!(distr_range2_i32, i32, -200_000_000i32, 800_000_000);
distr_range2_int!(distr_range2_i64, i64, 3i64, 134217671);

macro_rules! distr_float {
($fnn:ident, $distr:expr) => {
#[bench]
Expand Down
3 changes: 1 addition & 2 deletions src/distributions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use Rng;
pub use self::default::Default;
pub use self::uniform::{uniform, codepoint, ascii_word_char};
pub use self::uniform::{Uniform, Uniform01, Open01, Closed01, AsciiWordChar};
pub use self::range::{Range};
pub use self::range::Range;

#[cfg(feature="std")]
pub use self::gamma::{Gamma, ChiSquared, FisherF, StudentT};
Expand All @@ -39,7 +39,6 @@ mod uniform;
mod ziggurat_tables;

pub mod range;
pub mod range2;

#[cfg(feature="std")]
pub mod gamma;
Expand Down
Loading