combinations_with_replacement.rs 1020 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. use criterion::{black_box, criterion_group, criterion_main, Criterion};
  2. use itertools::Itertools;
  3. fn comb_replacement_n10_k5(c: &mut Criterion) {
  4. c.bench_function("comb replacement n10k5", move |b| {
  5. b.iter(|| {
  6. for i in (0..10).combinations_with_replacement(5) {
  7. black_box(i);
  8. }
  9. })
  10. });
  11. }
  12. fn comb_replacement_n5_k10(c: &mut Criterion) {
  13. c.bench_function("comb replacement n5 k10", move |b| {
  14. b.iter(|| {
  15. for i in (0..5).combinations_with_replacement(10) {
  16. black_box(i);
  17. }
  18. })
  19. });
  20. }
  21. fn comb_replacement_n10_k10(c: &mut Criterion) {
  22. c.bench_function("comb replacement n10 k10", move |b| {
  23. b.iter(|| {
  24. for i in (0..10).combinations_with_replacement(10) {
  25. black_box(i);
  26. }
  27. })
  28. });
  29. }
  30. criterion_group!(
  31. benches,
  32. comb_replacement_n10_k5,
  33. comb_replacement_n5_k10,
  34. comb_replacement_n10_k10,
  35. );
  36. criterion_main!(benches);