From bef66df7e422a8a30d9e2d32e948bb886b502738 Mon Sep 17 00:00:00 2001 From: David Peter Date: Mon, 5 Oct 2026 10:43:13 +0200 Subject: [PATCH] Restore original quantity trait and comments --- src/benchmark/mod.rs | 1 - src/quantity.rs | 4 ---- src/util/statistics.rs | 38 +++++++++++++++----------------------- 3 files changed, 15 insertions(+), 28 deletions(-) diff --git a/src/benchmark/mod.rs b/src/benchmark/mod.rs index e8bc25e..7b6f965 100644 --- a/src/benchmark/mod.rs +++ b/src/benchmark/mod.rs @@ -442,7 +442,6 @@ impl<'a> Benchmark<'a> { self.run_cleanup_command(self.command.get_parameters().iter().cloned(), output_policy)?; - // Keep the existing export representation: seconds and integer byte counts. Ok(BenchmarkResult { command: self.command.get_name(), command_with_unused_parameters: self.command.get_name_with_unused_parameters(), diff --git a/src/quantity.rs b/src/quantity.rs index 593d376..aeaa356 100644 --- a/src/quantity.rs +++ b/src/quantity.rs @@ -1,7 +1,3 @@ -//! Typed quantities for benchmark measurements. -//! -//! Both time and information use `f64` storage. Whole-byte counts are exact up to 8 PiB. - use std::marker::PhantomData; pub use uom::num_traits::Zero; diff --git a/src/util/statistics.rs b/src/util/statistics.rs index b019cf5..0802f32 100644 --- a/src/util/statistics.rs +++ b/src/util/statistics.rs @@ -61,57 +61,49 @@ where } } -/// Access a quantity in its base unit for statistical operations. -pub trait RawValue { - fn raw_value(&self) -> f64; - fn from_raw_value(value: f64) -> Self; +/// This is just sad, but after several hours trying to figure out how to write +/// a generic `standard_deviation` function using `uom` quantities, I gave up. +pub trait UnsafeRawValue { + fn unsafe_raw_value(&self) -> f64; + fn unsafe_from_raw_value(value: f64) -> Self; } -impl RawValue for Time { - fn raw_value(&self) -> f64 { +impl UnsafeRawValue for Time { + fn unsafe_raw_value(&self) -> f64 { self.get::() } - fn from_raw_value(value: f64) -> Self { + fn unsafe_from_raw_value(value: f64) -> Self { Time::new::(value) } } -impl RawValue for Information { - fn raw_value(&self) -> f64 { +impl UnsafeRawValue for Information { + fn unsafe_raw_value(&self) -> f64 { self.get::() } - fn from_raw_value(value: f64) -> Self { + fn unsafe_from_raw_value(value: f64) -> Self { Information::new::(value) } } -impl RawValue for f64 { - fn raw_value(&self) -> f64 { - *self - } - fn from_raw_value(value: f64) -> Self { - value - } -} - /// Sample standard deviation, using an already computed mean. -pub fn standard_deviation(values: &[Q], mean: Q) -> Q { - let mean = mean.raw_value(); +pub fn standard_deviation(values: &[Q], mean: Q) -> Q { + let mean = mean.unsafe_raw_value(); assert!( values.len() > 1, "standard deviation requires at least two measurements" ); let sum = values .iter() - .map(|value| (value.raw_value() - mean) * (value.raw_value() - mean)) + .map(|value| (value.unsafe_raw_value() - mean) * (value.unsafe_raw_value() - mean)) .fold(0.0, |sum, deviation| sum + deviation); assert!(sum >= 0.0, "invalid sum of squared deviations"); // Preserve the operation order of statistical 1.0: dividing by n - 1 // before taking the square root also preserves exported floating-point values. - Q::from_raw_value((sum / (values.len() as f64 - 1.0)).sqrt()) + Q::unsafe_from_raw_value((sum / (values.len() as f64 - 1.0)).sqrt()) } #[cfg(test)]