From 06d3c886fe4c37b3e4fbaf4caf7da96e5c575630 Mon Sep 17 00:00:00 2001 From: Anders Olsson Date: Fri, 24 Apr 2026 06:43:00 +0200 Subject: [PATCH] bench: capture T0 baseline; expose pi/tau accessors; fix div panic MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Promotes Gaussian::pi and Gaussian::tau to public so benches/gaussian.rs compiles, then captures baseline numbers for the T0 acceptance gate. - Fixes the divide bench: g1/g2 panicked (g1 has lower precision than g2; cavity requires pi_num >= pi_den). Swapped to g2/g1 (well-defined). Baseline on Apple M5 Pro: Batch::iteration 29.840 µs Gaussian::mul 1.568 ns (vs ~220 ps for add/sub — hot path) Gaussian::div 1.572 ns --- benches/baseline.txt | 12 ++++++++++++ benches/gaussian.rs | 5 ++++- src/gaussian.rs | 4 ++-- 3 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 benches/baseline.txt diff --git a/benches/baseline.txt b/benches/baseline.txt new file mode 100644 index 0000000..4e912a0 --- /dev/null +++ b/benches/baseline.txt @@ -0,0 +1,12 @@ +# Baseline numbers captured before T0 changes +# Hardware: lrrr.local / Apple M5 Pro +# Date: 2026-04-24 + +Batch::iteration 29.840 µs +Gaussian::add 219.58 ps +Gaussian::sub 219.41 ps +Gaussian::mul 1.568 ns +Gaussian::div 1.572 ns +Gaussian::pi 262.89 ps +Gaussian::tau 262.47 ps +Gaussian::pi_tau_combined 219.40 ps diff --git a/benches/gaussian.rs b/benches/gaussian.rs index 87b9361..1ca1d5e 100644 --- a/benches/gaussian.rs +++ b/benches/gaussian.rs @@ -23,8 +23,11 @@ fn benchmark_gaussian_arithmetic(criterion: &mut Criterion) { }); // Benchmark division + // NOTE: numerator must have higher precision (smaller sigma) than the + // denominator in this representation; g2 (sigma=1) / g1 (sigma=8.33) is + // well-defined, whereas g1 / g2 underflows and panics in mu_sigma. criterion.bench_function("Gaussian::div", |bencher| { - bencher.iter(|| g1 / g2); + bencher.iter(|| g2 / g1); }); // Benchmark natural parameter conversions diff --git a/src/gaussian.rs b/src/gaussian.rs index 8e43099..1a9c290 100644 --- a/src/gaussian.rs +++ b/src/gaussian.rs @@ -13,7 +13,7 @@ impl Gaussian { Gaussian { mu, sigma } } - fn pi(&self) -> f64 { + pub fn pi(&self) -> f64 { if self.sigma > 0.0 { self.sigma.powi(-2) } else { @@ -21,7 +21,7 @@ impl Gaussian { } } - fn tau(&self) -> f64 { + pub fn tau(&self) -> f64 { if self.sigma > 0.0 { self.mu * self.pi() } else {