mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-02 03:33:59 +00:00
12d3f107c1
Avoid using `rand::thread_rng` in the stdlib benchmarks. This is kind of an anti-pattern because it introduces extra nondeterminism for no real reason. In thread_rng's case this comes both from the random seed and also from the reseeding operations it does, which occasionally does syscalls (which adds additional nondeterminism). The impact of this would be pretty small in most cases, but it's a good practice to avoid (particularly because avoiding it was not hard). Anyway, several of our benchmarks already did the right thing here anyway, so the change was pretty easy and mostly just applying it more universally. That said, the stdlib benchmarks aren't particularly stable (nor is our benchmark framework particularly great), so arguably this doesn't matter that much in practice. ~~Anyway, this also bumps the `rand` dev-dependency to 0.8, since it had fallen somewhat out of date.~~ Nevermind, too much of a headache.
29 lines
617 B
Rust
29 lines
617 B
Rust
// wasm32 does not support benches (no time).
|
|
#![cfg(not(target_arch = "wasm32"))]
|
|
#![feature(flt2dec)]
|
|
#![feature(int_log)]
|
|
#![feature(test)]
|
|
#![feature(trusted_random_access)]
|
|
|
|
extern crate test;
|
|
|
|
mod any;
|
|
mod ascii;
|
|
mod char;
|
|
mod fmt;
|
|
mod hash;
|
|
mod iter;
|
|
mod num;
|
|
mod ops;
|
|
mod pattern;
|
|
mod slice;
|
|
mod str;
|
|
|
|
/// Returns a `rand::Rng` seeded with a consistent seed.
|
|
///
|
|
/// This is done to avoid introducing nondeterminism in benchmark results.
|
|
fn bench_rng() -> rand_xorshift::XorShiftRng {
|
|
const SEED: [u8; 16] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15];
|
|
rand::SeedableRng::from_seed(SEED)
|
|
}
|