diff --git a/gossip/benches/weighted_shuffle.rs b/gossip/benches/weighted_shuffle.rs index 58a7e37ce6a328..09615c57bbca15 100644 --- a/gossip/benches/weighted_shuffle.rs +++ b/gossip/benches/weighted_shuffle.rs @@ -11,18 +11,28 @@ use { }; fn make_weights(rng: &mut R) -> Vec { - repeat_with(|| rng.gen_range(1..100)).take(1000).collect() + repeat_with(|| rng.gen_range(1..100)).take(4000).collect() } #[bench] -fn bench_weighted_shuffle(bencher: &mut Bencher) { +fn bench_weighted_shuffle_new(bencher: &mut Bencher) { + let mut rng = rand::thread_rng(); + bencher.iter(|| { + let weights = make_weights(&mut rng); + std::hint::black_box(WeightedShuffle::new("", &weights)); + }); +} + +#[bench] +fn bench_weighted_shuffle_shuffle(bencher: &mut Bencher) { let mut seed = [0u8; 32]; let mut rng = rand::thread_rng(); let weights = make_weights(&mut rng); + let weighted_shuffle = WeightedShuffle::new("", &weights); bencher.iter(|| { rng.fill(&mut seed[..]); - WeightedShuffle::new("", &weights) - .shuffle(&mut ChaChaRng::from_seed(seed)) - .collect::>() + let mut rng = ChaChaRng::from_seed(seed); + let shuffle = weighted_shuffle.clone().shuffle(&mut rng); + std::hint::black_box(shuffle.collect::>()); }); }