Restore original quantity trait and comments
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by David Peter · committed by David Peter · parent a8e56ef · Browse files · 3 files·+15 added−28 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+15 added−28 removed
- other:+15 added−28 removed
Provenance
- Commit
bef66df- Tree
bdfdf13- Author
David Peter <sharkdp@users.noreply.github.com>- Committer
David Peter <sharkdp@users.noreply.github.com>- Parent
a8e56ef
3 files changed+15 added−28 removed
modified:src/benchmark/mod.rs-1 removed
440 unmodified lines441 }442 443 self.run_cleanup_command(self.command.get_parameters().iter().cloned(), output_policy)?;444 445- // Keep the existing export representation: seconds and integer byte counts.445 Ok(BenchmarkResult {446 command: self.command.get_name(),447 command_with_unused_parameters: self.command.get_name_with_unused_parameters(),448 mean: t_mean.get::<second>(),33 unmodified linesmodified:src/util/statistics.rs+15 added-23 removed
59 unmodified lines60 values[len / 2]61 }62 }63 64+/// This is just sad, but after several hours trying to figure out how to write64-/// Access a quantity in its base unit for statistical operations.65-pub trait RawValue {66- fn raw_value(&self) -> f64;67- fn from_raw_value(value: f64) -> Self;65+/// a generic `standard_deviation` function using `uom` quantities, I gave up.66+pub trait UnsafeRawValue {67+ fn unsafe_raw_value(&self) -> f64;68+ fn unsafe_from_raw_value(value: f64) -> Self;69 }70 70-impl RawValue for Time {71- fn raw_value(&self) -> f64 {71+impl UnsafeRawValue for Time {72+ fn unsafe_raw_value(&self) -> f64 {73 self.get::<second>()74 }75 75- fn from_raw_value(value: f64) -> Self {76+ fn unsafe_from_raw_value(value: f64) -> Self {77 Time::new::<second>(value)78 }79 }80 80-impl RawValue for Information {81- fn raw_value(&self) -> f64 {81+impl UnsafeRawValue for Information {82+ fn unsafe_raw_value(&self) -> f64 {83 self.get::<byte>()84 }85 85- fn from_raw_value(value: f64) -> Self {86+ fn unsafe_from_raw_value(value: f64) -> Self {87 Information::new::<byte>(value)88 }89 }90 90-impl RawValue for f64 {91- fn raw_value(&self) -> f64 {92- *self93- }94- fn from_raw_value(value: f64) -> Self {95- value96- }97-}98-91 /// Sample standard deviation, using an already computed mean.100-pub fn standard_deviation<Q: RawValue>(values: &[Q], mean: Q) -> Q {101- let mean = mean.raw_value();92+pub fn standard_deviation<Q: UnsafeRawValue>(values: &[Q], mean: Q) -> Q {93+ let mean = mean.unsafe_raw_value();94 assert!(95 values.len() > 1,96 "standard deviation requires at least two measurements"97 );98 let sum = values99 .iter()108- .map(|value| (value.raw_value() - mean) * (value.raw_value() - mean))100+ .map(|value| (value.unsafe_raw_value() - mean) * (value.unsafe_raw_value() - mean))101 .fold(0.0, |sum, deviation| sum + deviation);102 assert!(sum >= 0.0, "invalid sum of squared deviations");103 104 // Preserve the operation order of statistical 1.0: dividing by n - 1105 // before taking the square root also preserves exported floating-point values.114- Q::from_raw_value((sum / (values.len() as f64 - 1.0)).sqrt())106+ Q::unsafe_from_raw_value((sum / (values.len() as f64 - 1.0)).sqrt())107 }108 109 #[cfg(test)]110 mod tests {85 unmodified linesmodified:src/quantity.rs-4 removed
1-//! Typed quantities for benchmark measurements.2-//!3-//! Both time and information use `f64` storage. Whole-byte counts are exact up to 8 PiB.4-1 use std::marker::PhantomData;2 3 pub use uom::num_traits::Zero;4 pub use uom::si::f64::{Information, Ratio, Time};41 unmodified lines