Add inline attribute to SampleRange::construct_range
This improves the benchmark for sample in 11% and for shuffle in 16%.
diff --git a/benches/bench.rs b/benches/bench.rs
index 45a9666..5fa92bd 100644
--- a/benches/bench.rs
+++ b/benches/bench.rs
@@ -10,7 +10,7 @@
use std::mem::size_of;
use test::{black_box, Bencher};
use rand::{XorShiftRng, StdRng, IsaacRng, Isaac64Rng, Rng};
-use rand::{OsRng, weak_rng};
+use rand::{OsRng, sample, weak_rng};
#[bench]
fn rand_xorshift(b: &mut Bencher) {
@@ -86,3 +86,12 @@
rng.shuffle(x);
})
}
+
+#[bench]
+fn rand_sample_10_of_100(b: &mut Bencher) {
+ let mut rng = weak_rng();
+ let x : &[usize] = &[1; 100];
+ b.iter(|| {
+ sample(&mut rng, x, 10);
+ })
+}
diff --git a/src/distributions/range.rs b/src/distributions/range.rs
index 3cf47be..3a3f3e7 100644
--- a/src/distributions/range.rs
+++ b/src/distributions/range.rs
@@ -96,6 +96,7 @@
// "bit-equal", so casting between them is a no-op & a
// bijection.
+ #[inline]
fn construct_range(low: $ty, high: $ty) -> Range<$ty> {
let range = (w(high as $unsigned) - w(low as $unsigned)).0;
let unsigned_max: $unsigned = ::std::$unsigned::MAX;
@@ -112,6 +113,7 @@
accept_zone: zone as $ty
}
}
+
#[inline]
fn sample_range<R: Rng>(r: &Range<$ty>, rng: &mut R) -> $ty {
loop {