summaryrefslogtreecommitdiffstats
path: root/vendor/rand-0.7.3/benches
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/rand-0.7.3/benches')
-rw-r--r--vendor/rand-0.7.3/benches/generators.rs165
-rw-r--r--vendor/rand-0.7.3/benches/misc.rs140
-rw-r--r--vendor/rand-0.7.3/benches/seq.rs179
-rw-r--r--vendor/rand-0.7.3/benches/weighted.rs36
4 files changed, 0 insertions, 520 deletions
diff --git a/vendor/rand-0.7.3/benches/generators.rs b/vendor/rand-0.7.3/benches/generators.rs
deleted file mode 100644
index 3e264083d..000000000
--- a/vendor/rand-0.7.3/benches/generators.rs
+++ /dev/null
@@ -1,165 +0,0 @@
-// Copyright 2018 Developers of the Rand project.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-#![feature(test)]
-#![allow(non_snake_case)]
-
-extern crate test;
-
-const RAND_BENCH_N: u64 = 1000;
-const BYTES_LEN: usize = 1024;
-
-use std::mem::size_of;
-use test::{black_box, Bencher};
-
-use rand::prelude::*;
-use rand::rngs::adapter::ReseedingRng;
-use rand::rngs::{mock::StepRng, OsRng};
-use rand_chacha::{ChaCha12Rng, ChaCha20Core, ChaCha20Rng, ChaCha8Rng};
-use rand_hc::Hc128Rng;
-use rand_pcg::{Pcg32, Pcg64, Pcg64Mcg};
-
-macro_rules! gen_bytes {
- ($fnn:ident, $gen:expr) => {
- #[bench]
- fn $fnn(b: &mut Bencher) {
- let mut rng = $gen;
- let mut buf = [0u8; BYTES_LEN];
- b.iter(|| {
- for _ in 0..RAND_BENCH_N {
- rng.fill_bytes(&mut buf);
- black_box(buf);
- }
- });
- b.bytes = BYTES_LEN as u64 * RAND_BENCH_N;
- }
- };
-}
-
-gen_bytes!(gen_bytes_step, StepRng::new(0, 1));
-gen_bytes!(gen_bytes_pcg32, Pcg32::from_entropy());
-gen_bytes!(gen_bytes_pcg64, Pcg64::from_entropy());
-gen_bytes!(gen_bytes_pcg64mcg, Pcg64Mcg::from_entropy());
-gen_bytes!(gen_bytes_chacha8, ChaCha8Rng::from_entropy());
-gen_bytes!(gen_bytes_chacha12, ChaCha12Rng::from_entropy());
-gen_bytes!(gen_bytes_chacha20, ChaCha20Rng::from_entropy());
-gen_bytes!(gen_bytes_hc128, Hc128Rng::from_entropy());
-gen_bytes!(gen_bytes_std, StdRng::from_entropy());
-#[cfg(feature = "small_rng")]
-gen_bytes!(gen_bytes_small, SmallRng::from_entropy());
-gen_bytes!(gen_bytes_os, OsRng);
-
-macro_rules! gen_uint {
- ($fnn:ident, $ty:ty, $gen:expr) => {
- #[bench]
- fn $fnn(b: &mut Bencher) {
- let mut rng = $gen;
- b.iter(|| {
- let mut accum: $ty = 0;
- for _ in 0..RAND_BENCH_N {
- accum = accum.wrapping_add(rng.gen::<$ty>());
- }
- accum
- });
- b.bytes = size_of::<$ty>() as u64 * RAND_BENCH_N;
- }
- };
-}
-
-gen_uint!(gen_u32_step, u32, StepRng::new(0, 1));
-gen_uint!(gen_u32_pcg32, u32, Pcg32::from_entropy());
-gen_uint!(gen_u32_pcg64, u32, Pcg64::from_entropy());
-gen_uint!(gen_u32_pcg64mcg, u32, Pcg64Mcg::from_entropy());
-gen_uint!(gen_u32_chacha8, u32, ChaCha8Rng::from_entropy());
-gen_uint!(gen_u32_chacha12, u32, ChaCha12Rng::from_entropy());
-gen_uint!(gen_u32_chacha20, u32, ChaCha20Rng::from_entropy());
-gen_uint!(gen_u32_hc128, u32, Hc128Rng::from_entropy());
-gen_uint!(gen_u32_std, u32, StdRng::from_entropy());
-#[cfg(feature = "small_rng")]
-gen_uint!(gen_u32_small, u32, SmallRng::from_entropy());
-gen_uint!(gen_u32_os, u32, OsRng);
-
-gen_uint!(gen_u64_step, u64, StepRng::new(0, 1));
-gen_uint!(gen_u64_pcg32, u64, Pcg32::from_entropy());
-gen_uint!(gen_u64_pcg64, u64, Pcg64::from_entropy());
-gen_uint!(gen_u64_pcg64mcg, u64, Pcg64Mcg::from_entropy());
-gen_uint!(gen_u64_chacha8, u64, ChaCha8Rng::from_entropy());
-gen_uint!(gen_u64_chacha12, u64, ChaCha12Rng::from_entropy());
-gen_uint!(gen_u64_chacha20, u64, ChaCha20Rng::from_entropy());
-gen_uint!(gen_u64_hc128, u64, Hc128Rng::from_entropy());
-gen_uint!(gen_u64_std, u64, StdRng::from_entropy());
-#[cfg(feature = "small_rng")]
-gen_uint!(gen_u64_small, u64, SmallRng::from_entropy());
-gen_uint!(gen_u64_os, u64, OsRng);
-
-macro_rules! init_gen {
- ($fnn:ident, $gen:ident) => {
- #[bench]
- fn $fnn(b: &mut Bencher) {
- let mut rng = Pcg32::from_entropy();
- b.iter(|| {
- let r2 = $gen::from_rng(&mut rng).unwrap();
- r2
- });
- }
- };
-}
-
-init_gen!(init_pcg32, Pcg32);
-init_gen!(init_pcg64, Pcg64);
-init_gen!(init_pcg64mcg, Pcg64Mcg);
-init_gen!(init_hc128, Hc128Rng);
-init_gen!(init_chacha, ChaCha20Rng);
-
-const RESEEDING_BYTES_LEN: usize = 1024 * 1024;
-const RESEEDING_BENCH_N: u64 = 16;
-
-macro_rules! reseeding_bytes {
- ($fnn:ident, $thresh:expr) => {
- #[bench]
- fn $fnn(b: &mut Bencher) {
- let mut rng = ReseedingRng::new(ChaCha20Core::from_entropy(), $thresh * 1024, OsRng);
- let mut buf = [0u8; RESEEDING_BYTES_LEN];
- b.iter(|| {
- for _ in 0..RESEEDING_BENCH_N {
- rng.fill_bytes(&mut buf);
- black_box(&buf);
- }
- });
- b.bytes = RESEEDING_BYTES_LEN as u64 * RESEEDING_BENCH_N;
- }
- };
-}
-
-reseeding_bytes!(reseeding_chacha20_4k, 4);
-reseeding_bytes!(reseeding_chacha20_16k, 16);
-reseeding_bytes!(reseeding_chacha20_32k, 32);
-reseeding_bytes!(reseeding_chacha20_64k, 64);
-reseeding_bytes!(reseeding_chacha20_256k, 256);
-reseeding_bytes!(reseeding_chacha20_1M, 1024);
-
-
-macro_rules! threadrng_uint {
- ($fnn:ident, $ty:ty) => {
- #[bench]
- fn $fnn(b: &mut Bencher) {
- let mut rng = thread_rng();
- b.iter(|| {
- let mut accum: $ty = 0;
- for _ in 0..RAND_BENCH_N {
- accum = accum.wrapping_add(rng.gen::<$ty>());
- }
- accum
- });
- b.bytes = size_of::<$ty>() as u64 * RAND_BENCH_N;
- }
- };
-}
-
-threadrng_uint!(thread_rng_u32, u32);
-threadrng_uint!(thread_rng_u64, u64);
diff --git a/vendor/rand-0.7.3/benches/misc.rs b/vendor/rand-0.7.3/benches/misc.rs
deleted file mode 100644
index e46137f19..000000000
--- a/vendor/rand-0.7.3/benches/misc.rs
+++ /dev/null
@@ -1,140 +0,0 @@
-// Copyright 2018 Developers of the Rand project.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-#![feature(test)]
-
-extern crate test;
-
-const RAND_BENCH_N: u64 = 1000;
-
-use test::Bencher;
-
-use rand::distributions::{Bernoulli, Distribution, Standard};
-use rand::prelude::*;
-use rand_pcg::{Pcg32, Pcg64Mcg};
-
-#[bench]
-fn misc_gen_bool_const(b: &mut Bencher) {
- let mut rng = Pcg32::from_rng(&mut thread_rng()).unwrap();
- b.iter(|| {
- let mut accum = true;
- for _ in 0..crate::RAND_BENCH_N {
- accum ^= rng.gen_bool(0.18);
- }
- accum
- })
-}
-
-#[bench]
-fn misc_gen_bool_var(b: &mut Bencher) {
- let mut rng = Pcg32::from_rng(&mut thread_rng()).unwrap();
- b.iter(|| {
- let mut accum = true;
- let mut p = 0.18;
- for _ in 0..crate::RAND_BENCH_N {
- accum ^= rng.gen_bool(p);
- p += 0.0001;
- }
- accum
- })
-}
-
-#[bench]
-fn misc_gen_ratio_const(b: &mut Bencher) {
- let mut rng = Pcg32::from_rng(&mut thread_rng()).unwrap();
- b.iter(|| {
- let mut accum = true;
- for _ in 0..crate::RAND_BENCH_N {
- accum ^= rng.gen_ratio(2, 3);
- }
- accum
- })
-}
-
-#[bench]
-fn misc_gen_ratio_var(b: &mut Bencher) {
- let mut rng = Pcg32::from_rng(&mut thread_rng()).unwrap();
- b.iter(|| {
- let mut accum = true;
- for i in 2..(crate::RAND_BENCH_N as u32 + 2) {
- accum ^= rng.gen_ratio(i, i + 1);
- }
- accum
- })
-}
-
-#[bench]
-fn misc_bernoulli_const(b: &mut Bencher) {
- let mut rng = Pcg32::from_rng(&mut thread_rng()).unwrap();
- b.iter(|| {
- let d = rand::distributions::Bernoulli::new(0.18).unwrap();
- let mut accum = true;
- for _ in 0..crate::RAND_BENCH_N {
- accum ^= rng.sample(d);
- }
- accum
- })
-}
-
-#[bench]
-fn misc_bernoulli_var(b: &mut Bencher) {
- let mut rng = Pcg32::from_rng(&mut thread_rng()).unwrap();
- b.iter(|| {
- let mut accum = true;
- let mut p = 0.18;
- for _ in 0..crate::RAND_BENCH_N {
- let d = Bernoulli::new(p).unwrap();
- accum ^= rng.sample(d);
- p += 0.0001;
- }
- accum
- })
-}
-
-#[bench]
-fn gen_1k_iter_repeat(b: &mut Bencher) {
- use std::iter;
- 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
- });
- b.bytes = 1024;
-}
-
-#[bench]
-fn gen_1k_sample_iter(b: &mut Bencher) {
- 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
- });
- b.bytes = 1024;
-}
-
-#[bench]
-fn gen_1k_gen_array(b: &mut Bencher) {
- 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();
- v
- });
- b.bytes = 1024;
-}
-
-#[bench]
-fn gen_1k_fill(b: &mut Bencher) {
- let mut rng = Pcg64Mcg::from_rng(&mut thread_rng()).unwrap();
- let mut buf = [0u64; 128];
- b.iter(|| {
- rng.fill(&mut buf[..]);
- buf
- });
- b.bytes = 1024;
-}
diff --git a/vendor/rand-0.7.3/benches/seq.rs b/vendor/rand-0.7.3/benches/seq.rs
deleted file mode 100644
index 7da2ff8a0..000000000
--- a/vendor/rand-0.7.3/benches/seq.rs
+++ /dev/null
@@ -1,179 +0,0 @@
-// Copyright 2018 Developers of the Rand project.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-#![feature(test)]
-#![allow(non_snake_case)]
-
-extern crate test;
-
-use test::Bencher;
-
-use rand::prelude::*;
-use rand::seq::*;
-use std::mem::size_of;
-
-// We force use of 32-bit RNG since seq code is optimised for use with 32-bit
-// generators on all platforms.
-use rand_pcg::Pcg32 as SmallRng;
-
-const RAND_BENCH_N: u64 = 1000;
-
-#[bench]
-fn seq_shuffle_100(b: &mut Bencher) {
- let mut rng = SmallRng::from_rng(thread_rng()).unwrap();
- let x: &mut [usize] = &mut [1; 100];
- b.iter(|| {
- x.shuffle(&mut rng);
- x[0]
- })
-}
-
-#[bench]
-fn seq_slice_choose_1_of_1000(b: &mut Bencher) {
- let mut rng = SmallRng::from_rng(thread_rng()).unwrap();
- let x: &mut [usize] = &mut [1; 1000];
- for i in 0..1000 {
- x[i] = i;
- }
- b.iter(|| {
- let mut s = 0;
- for _ in 0..RAND_BENCH_N {
- s += x.choose(&mut rng).unwrap();
- }
- s
- });
- b.bytes = size_of::<usize>() as u64 * crate::RAND_BENCH_N;
-}
-
-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 x: &[i32] = &[$amount; $length];
- let mut result = [0i32; $amount];
- b.iter(|| {
- // Collect full result to prevent unwanted shortcuts getting
- // first element (in case sample_indices returns an iterator).
- for (slot, sample) in result.iter_mut().zip(x.choose_multiple(&mut rng, $amount)) {
- *slot = *sample;
- }
- result[$amount - 1]
- })
- }
- };
-}
-
-seq_slice_choose_multiple!(seq_slice_choose_multiple_1_of_1000, 1, 1000);
-seq_slice_choose_multiple!(seq_slice_choose_multiple_950_of_1000, 950, 1000);
-seq_slice_choose_multiple!(seq_slice_choose_multiple_10_of_100, 10, 100);
-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 x: &mut [usize] = &mut [1; 1000];
- for i in 0..1000 {
- x[i] = i;
- }
- b.iter(|| {
- let mut s = 0;
- for _ in 0..RAND_BENCH_N {
- s += x.iter().choose(&mut rng).unwrap();
- }
- s
- });
- b.bytes = size_of::<usize>() as u64 * crate::RAND_BENCH_N;
-}
-
-#[derive(Clone)]
-struct UnhintedIterator<I: Iterator + Clone> {
- iter: I,
-}
-impl<I: Iterator + Clone> Iterator for UnhintedIterator<I> {
- type Item = I::Item;
-
- fn next(&mut self) -> Option<Self::Item> {
- self.iter.next()
- }
-}
-
-#[derive(Clone)]
-struct WindowHintedIterator<I: ExactSizeIterator + Iterator + Clone> {
- iter: I,
- window_size: usize,
-}
-impl<I: ExactSizeIterator + Iterator + Clone> Iterator for WindowHintedIterator<I> {
- type Item = I::Item;
-
- fn next(&mut self) -> Option<Self::Item> {
- self.iter.next()
- }
-
- fn size_hint(&self) -> (usize, Option<usize>) {
- (std::cmp::min(self.iter.len(), self.window_size), None)
- }
-}
-
-#[bench]
-fn seq_iter_unhinted_choose_from_1000(b: &mut Bencher) {
- let mut rng = SmallRng::from_rng(thread_rng()).unwrap();
- let x: &[usize] = &[1; 1000];
- b.iter(|| {
- UnhintedIterator { iter: x.iter() }
- .choose(&mut rng)
- .unwrap()
- })
-}
-
-#[bench]
-fn seq_iter_window_hinted_choose_from_1000(b: &mut Bencher) {
- let mut rng = SmallRng::from_rng(thread_rng()).unwrap();
- let x: &[usize] = &[1; 1000];
- b.iter(|| {
- WindowHintedIterator {
- iter: x.iter(),
- window_size: 7,
- }
- .choose(&mut rng)
- })
-}
-
-#[bench]
-fn seq_iter_choose_multiple_10_of_100(b: &mut Bencher) {
- let mut rng = SmallRng::from_rng(thread_rng()).unwrap();
- 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 x: &[usize] = &[1; 100];
- let mut buf = [0; 10];
- b.iter(|| x.iter().cloned().choose_multiple_fill(&mut rng, &mut buf))
-}
-
-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();
- b.iter(|| index::$fn(&mut rng, $length, $amount))
- }
- };
-}
-
-sample_indices!(misc_sample_indices_1_of_1k, sample, 1, 1000);
-sample_indices!(misc_sample_indices_10_of_1k, sample, 10, 1000);
-sample_indices!(misc_sample_indices_100_of_1k, sample, 100, 1000);
-sample_indices!(misc_sample_indices_100_of_1M, sample, 100, 1000_000);
-sample_indices!(misc_sample_indices_100_of_1G, sample, 100, 1000_000_000);
-sample_indices!(misc_sample_indices_200_of_1G, sample, 200, 1000_000_000);
-sample_indices!(misc_sample_indices_400_of_1G, sample, 400, 1000_000_000);
-sample_indices!(misc_sample_indices_600_of_1G, sample, 600, 1000_000_000);
diff --git a/vendor/rand-0.7.3/benches/weighted.rs b/vendor/rand-0.7.3/benches/weighted.rs
deleted file mode 100644
index 68722908a..000000000
--- a/vendor/rand-0.7.3/benches/weighted.rs
+++ /dev/null
@@ -1,36 +0,0 @@
-// Copyright 2019 Developers of the Rand project.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-#![feature(test)]
-
-extern crate test;
-
-use rand::distributions::WeightedIndex;
-use rand::Rng;
-use test::Bencher;
-
-#[bench]
-fn weighted_index_creation(b: &mut Bencher) {
- let mut rng = rand::thread_rng();
- let weights = [1u32, 2, 4, 0, 5, 1, 7, 1, 2, 3, 4, 5, 6, 7];
- b.iter(|| {
- let distr = WeightedIndex::new(weights.to_vec()).unwrap();
- rng.sample(distr)
- })
-}
-
-#[bench]
-fn weighted_index_modification(b: &mut Bencher) {
- let mut rng = rand::thread_rng();
- let weights = [1u32, 2, 3, 0, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7];
- let mut distr = WeightedIndex::new(weights.to_vec()).unwrap();
- b.iter(|| {
- distr.update_weights(&[(2, &4), (5, &1)]).unwrap();
- rng.sample(&distr)
- })
-}