diff --git a/benches/cff_scalar.rs b/benches/cff_scalar.rs index 17fb9492..df507037 100644 --- a/benches/cff_scalar.rs +++ b/benches/cff_scalar.rs @@ -1,5 +1,3 @@ -use std::{env, path::PathBuf}; - use _gammaloop::{ gammaloop_integrand::DefaultSample, graph::Graph, @@ -9,17 +7,20 @@ use _gammaloop::{ ExportSettings, GammaloopCompileOptions, }; use criterion::{criterion_group, criterion_main, Criterion}; +use rand::Rng; +use std::{env, path::PathBuf, time::Duration}; const COMPILED_DUMP: &str = "TMP_COMPILED"; fn kinematics_builder(n_indep_externals: usize, n_loops: usize) -> DefaultSample { let mut external_moms = vec![]; + let mut rng = rand::thread_rng(); for i in 0..n_indep_externals { external_moms.push(FourMomentum::from_args( F(i as f64), - F(i as f64 + 0.25), - F(i as f64 + 0.5), - F(i as f64 + 0.75), + F(i as f64 + rng.gen::() * 0.25), + F(i as f64 + rng.gen::() * 0.5), + F(i as f64 + rng.gen::() * 0.75), )); } @@ -27,9 +28,9 @@ fn kinematics_builder(n_indep_externals: usize, n_loops: usize) -> DefaultSample for i in n_indep_externals..n_indep_externals + n_loops { loop_moms.push(ThreeMomentum::new( - F(i as f64), - F(i as f64 + 0.33), - F(i as f64 + 0.66), + F(i as f64 * rng.gen::()), + F(i as f64 + 0.33 * rng.gen::()), + F(i as f64 + 0.66 * rng.gen::()), )); } @@ -72,71 +73,66 @@ fn criterion_benchmark(c: &mut Criterion) { let _ = symbolica::LicenseManager::set_license_key("GAMMALOOP_USER"); let mut group = c.benchmark_group("scalar cff benchmarks"); + group.measurement_time(Duration::from_secs(10)); let triangle_graph = load_helper("TEST_AMPLITUDE_massless_scalar_triangle/GL_OUTPUT", false); - let triangle_sample = kinematics_builder(2, 1); group.bench_function("Triangle", |b| { - b.iter_batched( - || &triangle_graph, - |graph| graph.evaluate_cff_expression(&triangle_sample, 0), + b.iter_batched_ref( + || kinematics_builder(2, 1), + |sample| triangle_graph.evaluate_cff_expression(sample, 0), criterion::BatchSize::SmallInput, ) }); let box_graph = load_helper("TEST_AMPLITUDE_scalar_massless_box/GL_OUTPUT", false); - let box_sample = kinematics_builder(3, 1); group.bench_function("Box", |b| { - b.iter_batched( - || &box_graph, - |graph| graph.evaluate_cff_expression(&box_sample, 0), + b.iter_batched_ref( + || kinematics_builder(3, 1), + |sample| box_graph.evaluate_cff_expression(sample, 0), criterion::BatchSize::SmallInput, ) }); let double_triangle_graph = load_helper("TEST_AMPLITUDE_scalar_double_triangle/GL_OUTPUT", false); - let double_triangle_sample = kinematics_builder(1, 2); group.bench_function("Double Triangle", |b| { - b.iter_batched( - || &double_triangle_graph, - |graph| graph.evaluate_cff_expression(&double_triangle_sample, 0), + b.iter_batched_ref( + || kinematics_builder(1, 2), + |sample| double_triangle_graph.evaluate_cff_expression(sample, 0), criterion::BatchSize::SmallInput, ) }); let isopod_graph = load_helper("TEST_AMPLITUDE_scalar_isopod/GL_OUTPUT", false); - let isopod_sample = kinematics_builder(2, 3); group.bench_function("Isopod (Triangle-Box-Box)", |b| { - b.iter_batched( - || &isopod_graph, - |graph| graph.evaluate_cff_expression(&isopod_sample, 0), + b.iter_batched_ref( + || kinematics_builder(2, 3), + |sample| isopod_graph.evaluate_cff_expression(sample, 0), criterion::BatchSize::SmallInput, ) }); let fishnet_2x2_graph = load_helper("TEST_AMPLITUDE_scalar_fishnet_2x2/GL_OUTPUT", false); - let fishnet_2x2_sample = kinematics_builder(3, 4); group.bench_function("Fishnet 2x2", |b| { - b.iter_batched( - || &fishnet_2x2_graph, - |graph| graph.evaluate_cff_expression(&fishnet_2x2_sample, 0), + b.iter_batched_ref( + || kinematics_builder(3, 4), + |sample| fishnet_2x2_graph.evaluate_cff_expression(sample, 0), criterion::BatchSize::SmallInput, ) }); let fishnet_2x3_graph = load_helper("TEST_AMPLITUDE_scalar_fishnet_2x3/GL_OUTPUT", true); - let fishnet_2x3_sample = kinematics_builder(3, 6); group.bench_function("Fishnet 2x3", |b| { - b.iter_batched( - || &fishnet_2x3_graph, - |graph| graph.evaluate_cff_expression(&fishnet_2x3_sample, 0), - criterion::BatchSize::LargeInput, + b.iter_batched_ref( + || (kinematics_builder(3, 6)), + |sample| fishnet_2x3_graph.evaluate_cff_expression(sample, 0), + criterion::BatchSize::SmallInput, ) });