Skip to content

Commit 60007f0

Browse files
committed
graph: Use seedable PRNG in stress
1 parent e5f59d7 commit 60007f0

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

graph/examples/stress.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ use std::iter::FromIterator;
44
use std::sync::atomic::{AtomicUsize, Ordering::SeqCst};
55

66
use graph::prelude::{lazy_static, q};
7-
use rand::{thread_rng, Rng};
7+
use rand::{rngs::SmallRng, thread_rng, Rng};
8+
use rand::{FromEntropy, SeedableRng};
89
use structopt::StructOpt;
910

1011
use graph::util::cache_weight::CacheWeight;
@@ -360,6 +361,9 @@ struct Opt {
360361
/// Always use objects of size `--obj-size`
361362
#[structopt(short, long)]
362363
fixed: bool,
364+
/// The seed of the random number generator
365+
#[structopt(long)]
366+
seed: Option<u64>,
363367
}
364368

365369
fn stress<T: Template<T, Item = T>>(opt: &Opt) {
@@ -373,7 +377,11 @@ fn stress<T: Template<T, Item = T>>(opt: &Opt) {
373377
opt.cache_size
374378
);
375379

376-
let mut rng = thread_rng();
380+
let mut rng = match opt.seed {
381+
None => SmallRng::from_entropy(),
382+
Some(seed) => SmallRng::seed_from_u64(seed),
383+
};
384+
377385
let base_mem = ALLOCATED.load(SeqCst);
378386
let print_mod = opt.niter / opt.print_count + 1;
379387
let mut should_print = true;

0 commit comments

Comments
 (0)