aboutsummaryrefslogtreecommitdiff
path: root/rand/benches
diff options
context:
space:
mode:
Diffstat (limited to 'rand/benches')
-rw-r--r--rand/benches/distributions.rs22
-rw-r--r--rand/benches/generators.rs40
2 files changed, 62 insertions, 0 deletions
diff --git a/rand/benches/distributions.rs b/rand/benches/distributions.rs
index 7ac1a6a..069a828 100644
--- a/rand/benches/distributions.rs
+++ b/rand/benches/distributions.rs
@@ -101,6 +101,26 @@ macro_rules! distr {
}
}
+macro_rules! distr_arr {
+ ($fnn:ident, $ty:ty, $distr:expr) => {
+ #[bench]
+ fn $fnn(b: &mut Bencher) {
+ let mut rng = SmallRng::from_entropy();
+ let distr = $distr;
+
+ b.iter(|| {
+ let mut accum = 0u32;
+ for _ in 0..::RAND_BENCH_N {
+ let x: $ty = distr.sample(&mut rng);
+ accum = accum.wrapping_add(x[0] as u32);
+ }
+ accum
+ });
+ b.bytes = size_of::<$ty>() as u64 * ::RAND_BENCH_N;
+ }
+ }
+}
+
// uniform
distr_int!(distr_uniform_i8, i8, Uniform::new(20i8, 100));
distr_int!(distr_uniform_i16, i16, Uniform::new(-500i16, 2000));
@@ -158,6 +178,8 @@ distr_float!(distr_cauchy, f64, Cauchy::new(4.2, 6.9));
distr_int!(distr_binomial, u64, Binomial::new(20, 0.7));
distr_int!(distr_poisson, u64, Poisson::new(4.0));
distr!(distr_bernoulli, bool, Bernoulli::new(0.18));
+distr_arr!(distr_circle, [f64; 2], UnitCircle::new());
+distr_arr!(distr_sphere_surface, [f64; 3], UnitSphereSurface::new());
// Weighted
distr_int!(distr_weighted_i8, usize, WeightedIndex::new(&[1i8, 2, 3, 4, 12, 0, 2, 1]).unwrap());
diff --git a/rand/benches/generators.rs b/rand/benches/generators.rs
index a12b5a6..a6e3a42 100644
--- a/rand/benches/generators.rs
+++ b/rand/benches/generators.rs
@@ -15,6 +15,7 @@ extern crate rand_chacha;
extern crate rand_hc;
extern crate rand_pcg;
extern crate rand_xorshift;
+extern crate rand_xoshiro;
const RAND_BENCH_N: u64 = 1000;
const BYTES_LEN: usize = 1024;
@@ -30,6 +31,9 @@ use rand_chacha::ChaChaRng;
use rand_hc::{Hc128Rng, Hc128Core};
use rand_pcg::{Lcg64Xsh32, Mcg128Xsl64};
use rand_xorshift::XorShiftRng;
+use rand_xoshiro::{Xoshiro256StarStar, Xoshiro256Plus, Xoshiro128StarStar,
+ Xoshiro128Plus, Xoroshiro128StarStar, Xoroshiro128Plus, SplitMix64,
+ Xoroshiro64StarStar, Xoroshiro64Star};
macro_rules! gen_bytes {
($fnn:ident, $gen:expr) => {
@@ -49,6 +53,15 @@ macro_rules! gen_bytes {
}
gen_bytes!(gen_bytes_xorshift, XorShiftRng::from_entropy());
+gen_bytes!(gen_bytes_xoshiro256starstar, Xoshiro256StarStar::from_entropy());
+gen_bytes!(gen_bytes_xoshiro256plus, Xoshiro256Plus::from_entropy());
+gen_bytes!(gen_bytes_xoshiro128starstar, Xoshiro128StarStar::from_entropy());
+gen_bytes!(gen_bytes_xoshiro128plus, Xoshiro128Plus::from_entropy());
+gen_bytes!(gen_bytes_xoroshiro128starstar, Xoroshiro128StarStar::from_entropy());
+gen_bytes!(gen_bytes_xoroshiro128plus, Xoroshiro128Plus::from_entropy());
+gen_bytes!(gen_bytes_xoroshiro64starstar, Xoroshiro64StarStar::from_entropy());
+gen_bytes!(gen_bytes_xoroshiro64star, Xoroshiro64Star::from_entropy());
+gen_bytes!(gen_bytes_splitmix64, SplitMix64::from_entropy());
gen_bytes!(gen_bytes_lcg64_xsh32, Lcg64Xsh32::from_entropy());
gen_bytes!(gen_bytes_mcg128_xsh64, Mcg128Xsl64::from_entropy());
gen_bytes!(gen_bytes_chacha20, ChaChaRng::from_entropy());
@@ -77,6 +90,15 @@ macro_rules! gen_uint {
}
gen_uint!(gen_u32_xorshift, u32, XorShiftRng::from_entropy());
+gen_uint!(gen_u32_xoshiro256starstar, u32, Xoshiro256StarStar::from_entropy());
+gen_uint!(gen_u32_xoshiro256plus, u32, Xoshiro256Plus::from_entropy());
+gen_uint!(gen_u32_xoshiro128starstar, u32, Xoshiro128StarStar::from_entropy());
+gen_uint!(gen_u32_xoshiro128plus, u32, Xoshiro128Plus::from_entropy());
+gen_uint!(gen_u32_xoroshiro128starstar, u32, Xoroshiro128StarStar::from_entropy());
+gen_uint!(gen_u32_xoroshiro128plus, u32, Xoroshiro128Plus::from_entropy());
+gen_uint!(gen_u32_xoroshiro64starstar, u32, Xoroshiro64StarStar::from_entropy());
+gen_uint!(gen_u32_xoroshiro64star, u32, Xoroshiro64Star::from_entropy());
+gen_uint!(gen_u32_splitmix64, u32, SplitMix64::from_entropy());
gen_uint!(gen_u32_lcg64_xsh32, u32, Lcg64Xsh32::from_entropy());
gen_uint!(gen_u32_mcg128_xsh64, u32, Mcg128Xsl64::from_entropy());
gen_uint!(gen_u32_chacha20, u32, ChaChaRng::from_entropy());
@@ -88,6 +110,15 @@ gen_uint!(gen_u32_small, u32, SmallRng::from_entropy());
gen_uint!(gen_u32_os, u32, OsRng::new().unwrap());
gen_uint!(gen_u64_xorshift, u64, XorShiftRng::from_entropy());
+gen_uint!(gen_u64_xoshiro256starstar, u64, Xoshiro256StarStar::from_entropy());
+gen_uint!(gen_u64_xoshiro256plus, u64, Xoshiro256Plus::from_entropy());
+gen_uint!(gen_u64_xoshiro128starstar, u64, Xoshiro128StarStar::from_entropy());
+gen_uint!(gen_u64_xoshiro128plus, u64, Xoshiro128Plus::from_entropy());
+gen_uint!(gen_u64_xoroshiro128starstar, u64, Xoroshiro128StarStar::from_entropy());
+gen_uint!(gen_u64_xoroshiro128plus, u64, Xoroshiro128Plus::from_entropy());
+gen_uint!(gen_u64_xoroshiro64starstar, u64, Xoroshiro64StarStar::from_entropy());
+gen_uint!(gen_u64_xoroshiro64star, u64, Xoroshiro64Star::from_entropy());
+gen_uint!(gen_u64_splitmix64, u64, SplitMix64::from_entropy());
gen_uint!(gen_u64_lcg64_xsh32, u64, Lcg64Xsh32::from_entropy());
gen_uint!(gen_u64_mcg128_xsh64, u64, Mcg128Xsl64::from_entropy());
gen_uint!(gen_u64_chacha20, u64, ChaChaRng::from_entropy());
@@ -123,6 +154,15 @@ macro_rules! init_gen {
}
init_gen!(init_xorshift, XorShiftRng);
+init_gen!(init_xoshiro256starstar, Xoshiro256StarStar);
+init_gen!(init_xoshiro256plus, Xoshiro256Plus);
+init_gen!(init_xoshiro128starstar, Xoshiro128StarStar);
+init_gen!(init_xoshiro128plus, Xoshiro128Plus);
+init_gen!(init_xoroshiro128starstar, Xoroshiro128StarStar);
+init_gen!(init_xoroshiro128plus, Xoroshiro128Plus);
+init_gen!(init_xoroshiro64starstar, Xoroshiro64StarStar);
+init_gen!(init_xoroshiro64star, Xoroshiro64Star);
+init_gen!(init_splitmix64, SplitMix64);
init_gen!(init_lcg64_xsh32, Lcg64Xsh32);
init_gen!(init_mcg128_xsh64, Mcg128Xsl64);
init_gen!(init_hc128, Hc128Rng);