]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #96626 - thomcc:rand-bump, r=m-ou-se
authorbors <bors@rust-lang.org>
Thu, 5 May 2022 05:08:44 +0000 (05:08 +0000)
committerbors <bors@rust-lang.org>
Thu, 5 May 2022 05:08:44 +0000 (05:08 +0000)
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.

1  2 
Cargo.lock
library/core/benches/lib.rs

diff --combined Cargo.lock
index 417f3300f0b21c405e3d9cc375ce7ec65d9ef4ba,f4d2caea44300150fe26f90d6877adc9d61bda9e..188db89bc6c78a9007c8be40c57062202030b2e1
@@@ -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]]
index f1f1ae6e4635dee4b50a3cdc2458322c0b72e659,5e19b6db854891a47042d57ab9def061aedfea9c..a6c174d2fca2165f017a8c2bcb12a976f039aff4
@@@ -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)
+ }