Skip to content

Commit a9d9a88

Browse files
committed
temp
1 parent b912a09 commit a9d9a88

File tree

3 files changed

+71
-4
lines changed

3 files changed

+71
-4
lines changed

benches/uniform.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ use criterion::{criterion_group, criterion_main};
1010
use criterion::{BenchmarkId, Criterion};
1111
#[cfg(feature = "simd_support")] use packed_simd::*;
1212
use rand::distributions::uniform::{SampleUniform, Uniform, UniformSampler};
13-
use rand::prelude::*;
1413

15-
type BenchRng = SmallRng;
14+
type BenchRng = rand::rngs::SmallRng;
1615

1716
macro_rules! bench_dist_int_group {
1817
($name:literal, $T:ty, $f:ident, $g:expr, $inputs:expr) => {

benches/uniform_simd.rs

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Copyright 2021 Developers of the Rand project.
2+
//
3+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4+
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
5+
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
6+
// option. This file may not be copied, modified, or distributed
7+
// except according to those terms.
8+
9+
use criterion::{criterion_group, criterion_main};
10+
use criterion::{BenchmarkGroup, BenchmarkId, Criterion};
11+
use rand::distributions::uniform::{SampleUniform, UniformSampler};
12+
use rand::prelude::*;
13+
use packed_simd::*;
14+
15+
type BenchRng = SmallRng;
16+
17+
macro_rules! bench_simd_group {
18+
($name:literal, $T:ty, $f:ident, $g:expr, $inputs:expr) => {
19+
for input in $inputs {
20+
$g.bench_with_input(
21+
BenchmarkId::new($name, input.0),
22+
&input.1,
23+
|b, (low, high)| {
24+
let mut rng = BenchRng::from_entropy();
25+
b.iter(|| <$T as SampleUniform>::Sampler::$f(low, high, &mut rng))
26+
},
27+
);
28+
}
29+
$g.bench_function(BenchmarkId::new($name, "varying"), |b| {
30+
let (low, mut high) = ($inputs[0].1 .0, $inputs[1].1 .1);
31+
let mut rng = BenchRng::from_entropy();
32+
b.iter(|| {
33+
high = high.wrapping_add(1);
34+
<$T as SampleUniform>::Sampler::$f(low, high, &mut rng)
35+
})
36+
});
37+
};
38+
}
39+
40+
macro_rules! bench_simd {
41+
($c:expr, $T:ty, $high:expr) => {{
42+
let mut g = $c.benchmark_group(concat!("uniform_int_", stringify!($T)));
43+
let inputs = &[("high_reject", $high), ("low_reject", (-1, 2))];
44+
45+
bench_simd_group!("Old", $T, sample_single_inclusive, g, inputs);
46+
// bench_simd_group!("ONeill", $T, sample_single_inclusive_oneill, g, inputs);
47+
bench_simd_group!("Canon", $T, sample_single_inclusive_canon, g, inputs);
48+
// bench_simd_group!("Canon-Lemire", $T, sample_inclusive_canon_lemire, g, inputs);
49+
// bench_simd_group!("Bitmask", $T, sample_single_inclusive_bitmask, g, inputs);
50+
}};
51+
}
52+
53+
fn uniform_int(c: &mut Criterion) {
54+
// for i8/i16, we use 32-bit integers internally so rejection is most common near full-size
55+
// the exact values were determined with an exhaustive search
56+
bench_simd!(c, i8x16, (i8::MIN, 116));
57+
// bench_simd!(c, i16, (i16::MIN, 32407));
58+
// bench_simd!(c, i32, (i32::MIN, 1));
59+
// bench_simd!(c, i64, (i64::MIN, 1));
60+
// bench_simd!(c, i128, (i128::MIN, 1));
61+
}
62+
63+
criterion_group! {
64+
name = benches;
65+
config = Criterion::default();
66+
targets = uniform_int
67+
// targets = uniform_int_i8x16, uniform_int_i16, uniform_int_i32, uniform_int_i64, uniform_int_i128
68+
}
69+
criterion_main!(benches);

src/distributions/uniform.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,7 @@ pub use uniform_other::{UniformChar, UniformDuration};
178178
feature = "serde1",
179179
serde(bound(deserialize = "X::Sampler: Deserialize<'de>"))
180180
)]
181-
// HACK: field is pub
182-
pub struct Uniform<X: SampleUniform>(pub X::Sampler);
181+
pub struct Uniform<X: SampleUniform>(X::Sampler);
183182

184183
impl<X: SampleUniform> Uniform<X> {
185184
/// Create a new `Uniform` instance which samples uniformly from the half

0 commit comments

Comments
 (0)