From: bors Date: Thu, 5 May 2022 05:08:44 +0000 (+0000) Subject: Auto merge of #96626 - thomcc:rand-bump, r=m-ou-se X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=12d3f107c1634ed41a800e220ccf99b665d906d8;hp=-c;p=rust.git Auto merge of #96626 - thomcc:rand-bump, r=m-ou-se 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. --- 12d3f107c1634ed41a800e220ccf99b665d906d8 diff --combined Cargo.lock index 417f3300f0b,f4d2caea443..188db89bc6c --- a/Cargo.lock +++ b/Cargo.lock @@@ -448,10 -448,9 +448,10 @@@ dependencies = "lazy_static", "remove_dir_all", "serde_json", + "snapbox", "tar", "termcolor", - "toml_edit 0.13.4", + "toml_edit 0.14.3", "url 2.2.2", ] @@@ -828,6 -827,7 +828,7 @@@ name = "core version = "0.0.0" dependencies = [ "rand 0.7.3", + "rand_xorshift", ] [[package]] @@@ -4172,6 -4172,7 +4173,6 @@@ name = "rustc_parse_format version = "0.0.0" dependencies = [ "rustc_lexer", - "rustc_span", ] [[package]] @@@ -4245,7 -4246,6 +4246,7 @@@ dependencies = "rustc_serialize", "rustc_session", "rustc_span", + "tracing", ] [[package]] diff --combined library/core/benches/lib.rs index f1f1ae6e463,5e19b6db854..a6c174d2fca --- a/library/core/benches/lib.rs +++ b/library/core/benches/lib.rs @@@ -3,7 -3,6 +3,7 @@@ #![feature(flt2dec)] #![feature(int_log)] #![feature(test)] +#![feature(trusted_random_access)] extern crate test; @@@ -18,3 -17,11 +18,11 @@@ 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) + }