summaryrefslogtreecommitdiff
path: root/rand/benches/misc.rs
diff options
context:
space:
mode:
authorDaniel Mueller <deso@posteo.net>2020-01-02 08:32:06 -0800
committerDaniel Mueller <deso@posteo.net>2020-01-02 08:32:06 -0800
commitfd091b04316db9dc5fafadbd6bdbe60b127408a9 (patch)
treef202270f7ae5cedc513be03833a26148d9b5e219 /rand/benches/misc.rs
parent8161cdb26f98e65b39c603ddf7a614cc87c77a1c (diff)
downloadnitrocli-fd091b04316db9dc5fafadbd6bdbe60b127408a9.tar.gz
nitrocli-fd091b04316db9dc5fafadbd6bdbe60b127408a9.tar.bz2
Update nitrokey crate to 0.4.0
This change finally updates the version of the nitrokey crate that we consume to 0.4.0. Along with that we update rand_core, one of its dependencies, to 0.5.1. Further more we add cfg-if in version 0.1.10 and getrandom in version 0.1.13, both of which are now new (non-development) dependencies. Import subrepo nitrokey/:nitrokey at e81057037e9b4f370b64c0a030a725bc6bdfb870 Import subrepo cfg-if/:cfg-if at 4484a6faf816ff8058088ad857b0c6bb2f4b02b2 Import subrepo getrandom/:getrandom at d661aa7e1b8cc80b47dabe3d2135b3b47d2858af Import subrepo rand/:rand at d877ed528248b52d947e0484364a4e1ae59ca502
Diffstat (limited to 'rand/benches/misc.rs')
-rw-r--r--rand/benches/misc.rs60
1 files changed, 20 insertions, 40 deletions
diff --git a/rand/benches/misc.rs b/rand/benches/misc.rs
index 8fb3a83..4098686 100644
--- a/rand/benches/misc.rs
+++ b/rand/benches/misc.rs
@@ -9,20 +9,21 @@
#![feature(test)]
extern crate test;
-extern crate rand;
const RAND_BENCH_N: u64 = 1000;
use test::Bencher;
use rand::prelude::*;
+use rand::distributions::{Distribution, Standard, Bernoulli};
+use rand_pcg::{Pcg32, Pcg64Mcg};
#[bench]
fn misc_gen_bool_const(b: &mut Bencher) {
- let mut rng = StdRng::from_rng(&mut thread_rng()).unwrap();
+ let mut rng = Pcg32::from_rng(&mut thread_rng()).unwrap();
b.iter(|| {
let mut accum = true;
- for _ in 0..::RAND_BENCH_N {
+ for _ in 0..crate::RAND_BENCH_N {
accum ^= rng.gen_bool(0.18);
}
accum
@@ -31,11 +32,11 @@ fn misc_gen_bool_const(b: &mut Bencher) {
#[bench]
fn misc_gen_bool_var(b: &mut Bencher) {
- let mut rng = StdRng::from_rng(&mut thread_rng()).unwrap();
+ let mut rng = Pcg32::from_rng(&mut thread_rng()).unwrap();
b.iter(|| {
let mut accum = true;
let mut p = 0.18;
- for _ in 0..::RAND_BENCH_N {
+ for _ in 0..crate::RAND_BENCH_N {
accum ^= rng.gen_bool(p);
p += 0.0001;
}
@@ -45,10 +46,10 @@ fn misc_gen_bool_var(b: &mut Bencher) {
#[bench]
fn misc_gen_ratio_const(b: &mut Bencher) {
- let mut rng = StdRng::from_rng(&mut thread_rng()).unwrap();
+ let mut rng = Pcg32::from_rng(&mut thread_rng()).unwrap();
b.iter(|| {
let mut accum = true;
- for _ in 0..::RAND_BENCH_N {
+ for _ in 0..crate::RAND_BENCH_N {
accum ^= rng.gen_ratio(2, 3);
}
accum
@@ -57,10 +58,10 @@ fn misc_gen_ratio_const(b: &mut Bencher) {
#[bench]
fn misc_gen_ratio_var(b: &mut Bencher) {
- let mut rng = StdRng::from_rng(&mut thread_rng()).unwrap();
+ let mut rng = Pcg32::from_rng(&mut thread_rng()).unwrap();
b.iter(|| {
let mut accum = true;
- for i in 2..(::RAND_BENCH_N as u32 + 2) {
+ for i in 2..(crate::RAND_BENCH_N as u32 + 2) {
accum ^= rng.gen_ratio(i, i + 1);
}
accum
@@ -69,11 +70,11 @@ fn misc_gen_ratio_var(b: &mut Bencher) {
#[bench]
fn misc_bernoulli_const(b: &mut Bencher) {
- let mut rng = StdRng::from_rng(&mut thread_rng()).unwrap();
+ let mut rng = Pcg32::from_rng(&mut thread_rng()).unwrap();
b.iter(|| {
- let d = rand::distributions::Bernoulli::new(0.18);
+ let d = rand::distributions::Bernoulli::new(0.18).unwrap();
let mut accum = true;
- for _ in 0..::RAND_BENCH_N {
+ for _ in 0..crate::RAND_BENCH_N {
accum ^= rng.sample(d);
}
accum
@@ -82,12 +83,12 @@ fn misc_bernoulli_const(b: &mut Bencher) {
#[bench]
fn misc_bernoulli_var(b: &mut Bencher) {
- let mut rng = StdRng::from_rng(&mut thread_rng()).unwrap();
+ let mut rng = Pcg32::from_rng(&mut thread_rng()).unwrap();
b.iter(|| {
let mut accum = true;
let mut p = 0.18;
- for _ in 0..::RAND_BENCH_N {
- let d = rand::distributions::Bernoulli::new(p);
+ for _ in 0..crate::RAND_BENCH_N {
+ let d = Bernoulli::new(p).unwrap();
accum ^= rng.sample(d);
p += 0.0001;
}
@@ -95,30 +96,10 @@ fn misc_bernoulli_var(b: &mut Bencher) {
})
}
-macro_rules! sample_binomial {
- ($name:ident, $n:expr, $p:expr) => {
- #[bench]
- fn $name(b: &mut Bencher) {
- let mut rng = SmallRng::from_rng(&mut thread_rng()).unwrap();
- let (n, p) = ($n, $p);
- b.iter(|| {
- let d = rand::distributions::Binomial::new(n, p);
- rng.sample(d)
- })
- }
- }
-}
-
-sample_binomial!(misc_binomial_1, 1, 0.9);
-sample_binomial!(misc_binomial_10, 10, 0.9);
-sample_binomial!(misc_binomial_100, 100, 0.99);
-sample_binomial!(misc_binomial_1000, 1000, 0.01);
-sample_binomial!(misc_binomial_1e12, 1000_000_000_000, 0.2);
-
#[bench]
fn gen_1k_iter_repeat(b: &mut Bencher) {
use std::iter;
- let mut rng = SmallRng::from_rng(&mut thread_rng()).unwrap();
+ let mut rng = Pcg64Mcg::from_rng(&mut thread_rng()).unwrap();
b.iter(|| {
let v: Vec<u64> = iter::repeat(()).map(|()| rng.gen()).take(128).collect();
v
@@ -128,8 +109,7 @@ fn gen_1k_iter_repeat(b: &mut Bencher) {
#[bench]
fn gen_1k_sample_iter(b: &mut Bencher) {
- use rand::distributions::{Distribution, Standard};
- let mut rng = SmallRng::from_rng(&mut thread_rng()).unwrap();
+ let mut rng = Pcg64Mcg::from_rng(&mut thread_rng()).unwrap();
b.iter(|| {
let v: Vec<u64> = Standard.sample_iter(&mut rng).take(128).collect();
v
@@ -139,7 +119,7 @@ fn gen_1k_sample_iter(b: &mut Bencher) {
#[bench]
fn gen_1k_gen_array(b: &mut Bencher) {
- let mut rng = SmallRng::from_rng(&mut thread_rng()).unwrap();
+ let mut rng = Pcg64Mcg::from_rng(&mut thread_rng()).unwrap();
b.iter(|| {
// max supported array length is 32!
let v: [[u64; 32]; 4] = rng.gen();
@@ -150,7 +130,7 @@ fn gen_1k_gen_array(b: &mut Bencher) {
#[bench]
fn gen_1k_fill(b: &mut Bencher) {
- let mut rng = SmallRng::from_rng(&mut thread_rng()).unwrap();
+ let mut rng = Pcg64Mcg::from_rng(&mut thread_rng()).unwrap();
let mut buf = [0u64; 128];
b.iter(|| {
rng.fill(&mut buf[..]);