diff --git a/benches/benches/seq_choose.rs b/benches/benches/seq_choose.rs index a664b91501..f833866acf 100644 --- a/benches/benches/seq_choose.rs +++ b/benches/benches/seq_choose.rs @@ -52,6 +52,30 @@ pub fn bench(c: &mut Criterion) { }); } + let lens = [(1, 1000), (950, 1000), (10, 100), (90, 100)]; + for (amount, len) in lens { + let name = format!("seq_slice_choose_multiple_weighted_{}_of_{}", amount, len); + c.bench_function(name.as_str(), |b| { + let mut rng = Pcg32::from_rng(&mut rand::rng()); + let mut buf = [0i32; 1000]; + rng.fill(&mut buf); + let x = black_box(&buf[..len]); + + let mut results_buf = [0i32; 950]; + let y = black_box(&mut results_buf[..amount]); + let amount = black_box(amount); + + b.iter(|| { + // Collect full result to prevent unwanted shortcuts getting + // first element (in case sample_indices returns an iterator). + for (slot, sample) in y.iter_mut().zip(x.choose_multiple_weighted(&mut rng, amount, |_| 1.0).unwrap()) { + *slot = *sample; + } + y[amount - 1] + }) + }); + } + c.bench_function("seq_iter_choose_multiple_10_of_100", |b| { let mut rng = Pcg32::from_rng(&mut rand::rng()); let mut buf = [0i32; 100];