Skip to content

Commit

Permalink
slight rework of benches
Browse files Browse the repository at this point in the history
  • Loading branch information
GraDje13 committed Aug 7, 2024
1 parent 44d9a75 commit cbfadcb
Showing 1 changed file with 29 additions and 33 deletions.
62 changes: 29 additions & 33 deletions benches/cff_scalar.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::{env, path::PathBuf};

use _gammaloop::{
gammaloop_integrand::DefaultSample,
graph::Graph,
Expand All @@ -9,27 +7,30 @@ 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<f64> {
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::<f64>() * 0.25),
F(i as f64 + rng.gen::<f64>() * 0.5),
F(i as f64 + rng.gen::<f64>() * 0.75),
));
}

let mut loop_moms = vec![];

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::<f64>()),
F(i as f64 + 0.33 * rng.gen::<f64>()),
F(i as f64 + 0.66 * rng.gen::<f64>()),
));
}

Expand Down Expand Up @@ -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,
)
});

Expand Down

0 comments on commit cbfadcb

Please sign in to comment.