Skip to content

Commit 2573e83

Browse files
committed
Add benchmarks of unit circle and sphere surface sampling
1 parent 19d3baf commit 2573e83

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

benches/distributions.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,26 @@ macro_rules! distr {
101101
}
102102
}
103103

104+
macro_rules! distr_arr {
105+
($fnn:ident, $ty:ty, $distr:expr) => {
106+
#[bench]
107+
fn $fnn(b: &mut Bencher) {
108+
let mut rng = SmallRng::from_entropy();
109+
let distr = $distr;
110+
111+
b.iter(|| {
112+
let mut accum = 0u32;
113+
for _ in 0..::RAND_BENCH_N {
114+
let x: $ty = distr.sample(&mut rng);
115+
accum = accum.wrapping_add(x[0] as u32);
116+
}
117+
accum
118+
});
119+
b.bytes = size_of::<$ty>() as u64 * ::RAND_BENCH_N;
120+
}
121+
}
122+
}
123+
104124
// uniform
105125
distr_int!(distr_uniform_i8, i8, Uniform::new(20i8, 100));
106126
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));
158178
distr_int!(distr_binomial, u64, Binomial::new(20, 0.7));
159179
distr_int!(distr_poisson, u64, Poisson::new(4.0));
160180
distr!(distr_bernoulli, bool, Bernoulli::new(0.18));
181+
distr_arr!(distr_circle, [f64; 2], UnitCircle::new());
182+
distr_arr!(distr_sphere_surface, [f64; 3], UnitSphereSurface::new());
161183

162184
// Weighted
163185
distr_int!(distr_weighted_i8, usize, WeightedIndex::new(&[1i8, 2, 3, 4, 12, 0, 2, 1]).unwrap());

0 commit comments

Comments
 (0)