Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expands weighted-shuffle benchmarks #179

Merged
merged 1 commit into from
Mar 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions gossip/benches/weighted_shuffle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,28 @@ use {
};

fn make_weights<R: Rng>(rng: &mut R) -> Vec<u64> {
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::<Vec<_>>()
let mut rng = ChaChaRng::from_seed(seed);
let shuffle = weighted_shuffle.clone().shuffle(&mut rng);
std::hint::black_box(shuffle.collect::<Vec<_>>());
});
}
Loading