use std::fmt::Debug; use const_decimal::{Decimal, ScaledInteger}; use criterion::measurement::WallTime; use criterion::{black_box, BatchSize, BenchmarkGroup}; use num_traits::PrimInt; use prop::strategy::ValueTree; use prop::test_runner::TestRunner; use proptest::prelude::*; pub fn bench_all( group: &mut BenchmarkGroup<'_, WallTime>, lo_strategy: impl Strategy + Clone, hi_strategy: impl Strategy + Clone, ) where I: ScaledInteger + Debug, { primitive_mul::(group, lo_strategy.clone(), "lo"); decimal_mul::(group, lo_strategy, "lo"); primitive_mul::(group, hi_strategy.clone(), "hi"); decimal_mul::(group, hi_strategy, "hi"); } fn primitive_mul( group: &mut BenchmarkGroup<'_, WallTime>, strategy: impl Strategy + Clone, strategy_label: &str, ) where I: PrimInt, { // Use proptest to generate arbitrary input values. let mut runner = TestRunner::deterministic(); let input = (strategy.clone(), strategy); group.bench_function(&format!("primitive/mul/{strategy_label}"), |bencher| { bencher.iter_batched( || input.new_tree(&mut runner).unwrap().current(), |(a, b)| black_box(black_box(a) * black_box(b)), BatchSize::SmallInput, ) }); } fn decimal_mul( group: &mut BenchmarkGroup<'_, WallTime>, strategy: impl Strategy + Clone, strategy_label: &str, ) where I: ScaledInteger + Debug, { // Use proptest to generate arbitrary input values. let mut runner = TestRunner::deterministic(); let input = (strategy.clone(), strategy).prop_map(|(a, b)| (Decimal::<_, D>(a), Decimal::<_, D>(b))); group.bench_function(format!("decimal/mul/{strategy_label}"), |bencher| { bencher.iter_batched( || input.new_tree(&mut runner).unwrap().current(), |(a, b)| black_box(black_box(a) * black_box(b)), BatchSize::SmallInput, ) }); }