perfgate-stats
Descriptive statistics for performance data -- the numerical foundation of perfgate's budget evaluation pipeline.
Pure functions with no I/O dependencies. Used by perfgate-domain and can be
independently tested and versioned.
API
Summary Statistics
summarize_u64(values) -> U64Summary-- median, min, max, mean, stddevsummarize_f64(values) -> F64Summary-- same forf64samples
Median (pre-sorted)
median_u64_sorted(sorted)-- overflow-safeu64median via split-halvesmedian_f64_sorted(sorted)--f64median
Percentile
percentile(values, q)-- q-th percentile (q in [0, 1]) with linear interpolation between adjacent ranks
Mean and Variance
mean_and_variance(values) -> Option<(f64, f64)>-- arithmetic mean and Bessel-corrected sample variance using Welford's online algorithm for numerical stability; returnsNonefor empty or non-finite input
Example
use ;
let summary = summarize_u64.unwrap;
assert_eq!;
assert_eq!;
assert_eq!;
let p95 = percentile.unwrap;
let = mean_and_variance.unwrap;
Numerical Stability
mean_and_variance uses Welford's one-pass online algorithm, avoiding the
catastrophic cancellation that affects naive two-pass (sum-of-squares) methods.
Results are validated as finite before returning.
The u64 median uses a split-halves technique (a/2 + b/2 + remainder) to
avoid overflow at u64::MAX boundaries.
Testing
- Property-based (proptest): ordering invariants, overflow handling, percentile bounds, mean correctness against naive computation
- Benchmarks via Criterion (
cargo bench -p perfgate-stats)
License
Licensed under either Apache-2.0 or MIT.