-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,58 +7,61 @@ const RAND_BENCH_N: u64 = 1000; | |
|
||
use test::{black_box, Bencher}; | ||
|
||
use rand::{SeedableRng, SmallRng, Rng, thread_rng}; | ||
use rand::{SeedableRng, SmallRng, StdRng, Rng, thread_rng}; | ||
use rand::seq::*; | ||
|
||
#[bench] | ||
fn misc_gen_bool_const(b: &mut Bencher) { | ||
let mut rng = SmallRng::from_rng(&mut thread_rng()).unwrap(); | ||
let mut rng = StdRng::from_rng(&mut thread_rng()).unwrap(); | ||
b.iter(|| { | ||
// Can be evaluated at compile time. | ||
let mut accum = true; | ||
for _ in 0..::RAND_BENCH_N { | ||
accum ^= rng.gen_bool(0.18); | ||
} | ||
accum | ||
black_box(accum); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
pitdicker
Author
Owner
|
||
}) | ||
} | ||
|
||
#[bench] | ||
fn misc_gen_bool_var(b: &mut Bencher) { | ||
let mut rng = SmallRng::from_rng(&mut thread_rng()).unwrap(); | ||
let mut rng = StdRng::from_rng(&mut thread_rng()).unwrap(); | ||
b.iter(|| { | ||
let mut accum = true; | ||
let mut p = 0.18; | ||
black_box(&mut p); // Avoid constant folding. | ||
for _ in 0..::RAND_BENCH_N { | ||
black_box(rng.gen_bool(p)); | ||
accum ^= rng.gen_bool(p); | ||
p += 0.0001; | ||
} | ||
black_box(accum); | ||
}) | ||
} | ||
|
||
#[bench] | ||
fn misc_bernoulli_const(b: &mut Bencher) { | ||
let mut rng = SmallRng::from_rng(&mut thread_rng()).unwrap(); | ||
let mut rng = StdRng::from_rng(&mut thread_rng()).unwrap(); | ||
let d = rand::distributions::Bernoulli::new(0.18); | ||
b.iter(|| { | ||
// Can be evaluated at compile time. | ||
let mut accum = true; | ||
for _ in 0..::RAND_BENCH_N { | ||
accum ^= rng.sample(d); | ||
} | ||
accum | ||
black_box(accum); | ||
}) | ||
} | ||
|
||
#[bench] | ||
fn misc_bernoulli_var(b: &mut Bencher) { | ||
let mut rng = SmallRng::from_rng(&mut thread_rng()).unwrap(); | ||
let mut rng = StdRng::from_rng(&mut thread_rng()).unwrap(); | ||
b.iter(|| { | ||
let mut accum = true; | ||
let mut p = 0.18; | ||
black_box(&mut p); // Avoid constant folding. | ||
let d = rand::distributions::Bernoulli::new(p); | ||
for _ in 0..::RAND_BENCH_N { | ||
black_box(rng.sample(d)); | ||
let d = rand::distributions::Bernoulli::new(p); | ||
accum ^= rng.sample(d); | ||
p += 0.0001; | ||
} | ||
black_box(accum); | ||
}) | ||
} | ||
|
||
|
Isn't this
black_box
redundant?