diff --git a/benches/generators.rs b/benches/generators.rs index 02c91c6de7..a1ec029322 100644 --- a/benches/generators.rs +++ b/benches/generators.rs @@ -102,7 +102,7 @@ macro_rules! init_gen { fn $fnn(b: &mut Bencher) { let mut rng = Pcg32::from_entropy(); b.iter(|| { - let r2 = $gen::from_rng(&mut rng).unwrap(); + let r2 = $gen::from_rng(&mut rng); r2 }); } diff --git a/benches/misc.rs b/benches/misc.rs index f0b761f99e..44f522fdf5 100644 --- a/benches/misc.rs +++ b/benches/misc.rs @@ -20,7 +20,7 @@ use rand_pcg::{Pcg32, Pcg64Mcg}; #[bench] fn misc_gen_bool_const(b: &mut Bencher) { - let mut rng = Pcg32::from_rng(&mut thread_rng()).unwrap(); + let mut rng = Pcg32::from_rng(thread_rng()); b.iter(|| { let mut accum = true; for _ in 0..crate::RAND_BENCH_N { @@ -32,7 +32,7 @@ fn misc_gen_bool_const(b: &mut Bencher) { #[bench] fn misc_gen_bool_var(b: &mut Bencher) { - let mut rng = Pcg32::from_rng(&mut thread_rng()).unwrap(); + let mut rng = Pcg32::from_rng(thread_rng()); b.iter(|| { let mut accum = true; let mut p = 0.18; @@ -46,7 +46,7 @@ fn misc_gen_bool_var(b: &mut Bencher) { #[bench] fn misc_gen_ratio_const(b: &mut Bencher) { - let mut rng = Pcg32::from_rng(&mut thread_rng()).unwrap(); + let mut rng = Pcg32::from_rng(thread_rng()); b.iter(|| { let mut accum = true; for _ in 0..crate::RAND_BENCH_N { @@ -58,7 +58,7 @@ fn misc_gen_ratio_const(b: &mut Bencher) { #[bench] fn misc_gen_ratio_var(b: &mut Bencher) { - let mut rng = Pcg32::from_rng(&mut thread_rng()).unwrap(); + let mut rng = Pcg32::from_rng(thread_rng()); b.iter(|| { let mut accum = true; for i in 2..(crate::RAND_BENCH_N as u32 + 2) { @@ -70,7 +70,7 @@ fn misc_gen_ratio_var(b: &mut Bencher) { #[bench] fn misc_bernoulli_const(b: &mut Bencher) { - let mut rng = Pcg32::from_rng(&mut thread_rng()).unwrap(); + let mut rng = Pcg32::from_rng(thread_rng()); b.iter(|| { let d = rand::distributions::Bernoulli::new(0.18).unwrap(); let mut accum = true; @@ -83,7 +83,7 @@ fn misc_bernoulli_const(b: &mut Bencher) { #[bench] fn misc_bernoulli_var(b: &mut Bencher) { - let mut rng = Pcg32::from_rng(&mut thread_rng()).unwrap(); + let mut rng = Pcg32::from_rng(thread_rng()); b.iter(|| { let mut accum = true; let mut p = 0.18; @@ -99,7 +99,7 @@ fn misc_bernoulli_var(b: &mut Bencher) { #[bench] fn gen_1kb_u16_iter_repeat(b: &mut Bencher) { use core::iter; - let mut rng = Pcg64Mcg::from_rng(&mut thread_rng()).unwrap(); + let mut rng = Pcg64Mcg::from_rng(thread_rng()); b.iter(|| { let v: Vec = iter::repeat(()).map(|()| rng.gen()).take(512).collect(); v @@ -109,7 +109,7 @@ fn gen_1kb_u16_iter_repeat(b: &mut Bencher) { #[bench] fn gen_1kb_u16_sample_iter(b: &mut Bencher) { - let mut rng = Pcg64Mcg::from_rng(&mut thread_rng()).unwrap(); + let mut rng = Pcg64Mcg::from_rng(thread_rng()); b.iter(|| { let v: Vec = Standard.sample_iter(&mut rng).take(512).collect(); v @@ -119,7 +119,7 @@ fn gen_1kb_u16_sample_iter(b: &mut Bencher) { #[bench] fn gen_1kb_u16_gen_array(b: &mut Bencher) { - let mut rng = Pcg64Mcg::from_rng(&mut thread_rng()).unwrap(); + let mut rng = Pcg64Mcg::from_rng(thread_rng()); b.iter(|| { // max supported array length is 32! let v: [[u16; 32]; 16] = rng.gen(); @@ -130,7 +130,7 @@ fn gen_1kb_u16_gen_array(b: &mut Bencher) { #[bench] fn gen_1kb_u16_fill(b: &mut Bencher) { - let mut rng = Pcg64Mcg::from_rng(&mut thread_rng()).unwrap(); + let mut rng = Pcg64Mcg::from_rng(thread_rng()); let mut buf = [0u16; 512]; b.iter(|| { rng.fill(&mut buf[..]); @@ -142,7 +142,7 @@ fn gen_1kb_u16_fill(b: &mut Bencher) { #[bench] fn gen_1kb_u64_iter_repeat(b: &mut Bencher) { use core::iter; - let mut rng = Pcg64Mcg::from_rng(&mut thread_rng()).unwrap(); + let mut rng = Pcg64Mcg::from_rng(thread_rng()); b.iter(|| { let v: Vec = iter::repeat(()).map(|()| rng.gen()).take(128).collect(); v @@ -152,7 +152,7 @@ fn gen_1kb_u64_iter_repeat(b: &mut Bencher) { #[bench] fn gen_1kb_u64_sample_iter(b: &mut Bencher) { - let mut rng = Pcg64Mcg::from_rng(&mut thread_rng()).unwrap(); + let mut rng = Pcg64Mcg::from_rng(thread_rng()); b.iter(|| { let v: Vec = Standard.sample_iter(&mut rng).take(128).collect(); v @@ -162,7 +162,7 @@ fn gen_1kb_u64_sample_iter(b: &mut Bencher) { #[bench] fn gen_1kb_u64_gen_array(b: &mut Bencher) { - let mut rng = Pcg64Mcg::from_rng(&mut thread_rng()).unwrap(); + let mut rng = Pcg64Mcg::from_rng(thread_rng()); b.iter(|| { // max supported array length is 32! let v: [[u64; 32]; 4] = rng.gen(); @@ -173,7 +173,7 @@ fn gen_1kb_u64_gen_array(b: &mut Bencher) { #[bench] fn gen_1kb_u64_fill(b: &mut Bencher) { - let mut rng = Pcg64Mcg::from_rng(&mut thread_rng()).unwrap(); + let mut rng = Pcg64Mcg::from_rng(thread_rng()); let mut buf = [0u64; 128]; b.iter(|| { rng.fill(&mut buf[..]); diff --git a/benches/seq.rs b/benches/seq.rs index 8f5bea87f2..634480087a 100644 --- a/benches/seq.rs +++ b/benches/seq.rs @@ -25,7 +25,7 @@ const RAND_BENCH_N: u64 = 1000; #[bench] fn seq_shuffle_100(b: &mut Bencher) { - let mut rng = SmallRng::from_rng(thread_rng()).unwrap(); + let mut rng = SmallRng::from_rng(thread_rng()); let x: &mut [usize] = &mut [1; 100]; b.iter(|| { x.shuffle(&mut rng); @@ -35,7 +35,7 @@ fn seq_shuffle_100(b: &mut Bencher) { #[bench] fn seq_slice_choose_1_of_1000(b: &mut Bencher) { - let mut rng = SmallRng::from_rng(thread_rng()).unwrap(); + let mut rng = SmallRng::from_rng(thread_rng()); let x: &mut [usize] = &mut [1; 1000]; for (i, r) in x.iter_mut().enumerate() { *r = i; @@ -54,7 +54,7 @@ macro_rules! seq_slice_choose_multiple { ($name:ident, $amount:expr, $length:expr) => { #[bench] fn $name(b: &mut Bencher) { - let mut rng = SmallRng::from_rng(thread_rng()).unwrap(); + let mut rng = SmallRng::from_rng(thread_rng()); let x: &[i32] = &[$amount; $length]; let mut result = [0i32; $amount]; b.iter(|| { @@ -76,7 +76,7 @@ seq_slice_choose_multiple!(seq_slice_choose_multiple_90_of_100, 90, 100); #[bench] fn seq_iter_choose_from_1000(b: &mut Bencher) { - let mut rng = SmallRng::from_rng(thread_rng()).unwrap(); + let mut rng = SmallRng::from_rng(thread_rng()); let x: &mut [usize] = &mut [1; 1000]; for (i, r) in x.iter_mut().enumerate() { *r = i; @@ -122,7 +122,7 @@ impl Iterator for WindowHintedIterator< #[bench] fn seq_iter_unhinted_choose_from_1000(b: &mut Bencher) { - let mut rng = SmallRng::from_rng(thread_rng()).unwrap(); + let mut rng = SmallRng::from_rng(thread_rng()); let x: &[usize] = &[1; 1000]; b.iter(|| { UnhintedIterator { iter: x.iter() } @@ -133,7 +133,7 @@ fn seq_iter_unhinted_choose_from_1000(b: &mut Bencher) { #[bench] fn seq_iter_window_hinted_choose_from_1000(b: &mut Bencher) { - let mut rng = SmallRng::from_rng(thread_rng()).unwrap(); + let mut rng = SmallRng::from_rng(thread_rng()); let x: &[usize] = &[1; 1000]; b.iter(|| { WindowHintedIterator { @@ -146,14 +146,14 @@ fn seq_iter_window_hinted_choose_from_1000(b: &mut Bencher) { #[bench] fn seq_iter_choose_multiple_10_of_100(b: &mut Bencher) { - let mut rng = SmallRng::from_rng(thread_rng()).unwrap(); + let mut rng = SmallRng::from_rng(thread_rng()); let x: &[usize] = &[1; 100]; b.iter(|| x.iter().cloned().choose_multiple(&mut rng, 10)) } #[bench] fn seq_iter_choose_multiple_fill_10_of_100(b: &mut Bencher) { - let mut rng = SmallRng::from_rng(thread_rng()).unwrap(); + let mut rng = SmallRng::from_rng(thread_rng()); let x: &[usize] = &[1; 100]; let mut buf = [0; 10]; b.iter(|| x.iter().cloned().choose_multiple_fill(&mut rng, &mut buf)) @@ -163,7 +163,7 @@ macro_rules! sample_indices { ($name:ident, $fn:ident, $amount:expr, $length:expr) => { #[bench] fn $name(b: &mut Bencher) { - let mut rng = SmallRng::from_rng(thread_rng()).unwrap(); + let mut rng = SmallRng::from_rng(thread_rng()); b.iter(|| index::$fn(&mut rng, $length, $amount)) } }; @@ -182,7 +182,7 @@ macro_rules! sample_indices_rand_weights { ($name:ident, $amount:expr, $length:expr) => { #[bench] fn $name(b: &mut Bencher) { - let mut rng = SmallRng::from_rng(thread_rng()).unwrap(); + let mut rng = SmallRng::from_rng(thread_rng()); b.iter(|| { index::sample_weighted(&mut rng, $length, |idx| (1 + (idx % 100)) as u32, $amount) })