mirror of
https://github.com/sharkdp/hyperfine.git
synced 2026-11-03 09:23:00 +00:00
Restore original quantity trait and comments
This commit is contained in:
1 parent
a8e56efecc
commit
bef66df7e4
3 files changed
+15
-28
No files matched your search
@@ -442,7 +442,6 @@ impl<'a> Benchmark<'a> {
|
|||||||
|
|
||||||
self.run_cleanup_command(self.command.get_parameters().iter().cloned(), output_policy)?;
|
self.run_cleanup_command(self.command.get_parameters().iter().cloned(), output_policy)?;
|
||||||
|
|
||||||
// Keep the existing export representation: seconds and integer byte counts.
|
|
||||||
Ok(BenchmarkResult {
|
Ok(BenchmarkResult {
|
||||||
command: self.command.get_name(),
|
command: self.command.get_name(),
|
||||||
command_with_unused_parameters: self.command.get_name_with_unused_parameters(),
|
command_with_unused_parameters: self.command.get_name_with_unused_parameters(),
|
||||||
|
|||||||
@@ -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;
|
use std::marker::PhantomData;
|
||||||
|
|
||||||
pub use uom::num_traits::Zero;
|
pub use uom::num_traits::Zero;
|
||||||
|
|||||||
+15
-23
@@ -61,57 +61,49 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Access a quantity in its base unit for statistical operations.
|
/// This is just sad, but after several hours trying to figure out how to write
|
||||||
pub trait RawValue {
|
/// a generic `standard_deviation` function using `uom` quantities, I gave up.
|
||||||
fn raw_value(&self) -> f64;
|
pub trait UnsafeRawValue {
|
||||||
fn from_raw_value(value: f64) -> Self;
|
fn unsafe_raw_value(&self) -> f64;
|
||||||
|
fn unsafe_from_raw_value(value: f64) -> Self;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RawValue for Time {
|
impl UnsafeRawValue for Time {
|
||||||
fn raw_value(&self) -> f64 {
|
fn unsafe_raw_value(&self) -> f64 {
|
||||||
self.get::<second>()
|
self.get::<second>()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_raw_value(value: f64) -> Self {
|
fn unsafe_from_raw_value(value: f64) -> Self {
|
||||||
Time::new::<second>(value)
|
Time::new::<second>(value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RawValue for Information {
|
impl UnsafeRawValue for Information {
|
||||||
fn raw_value(&self) -> f64 {
|
fn unsafe_raw_value(&self) -> f64 {
|
||||||
self.get::<byte>()
|
self.get::<byte>()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_raw_value(value: f64) -> Self {
|
fn unsafe_from_raw_value(value: f64) -> Self {
|
||||||
Information::new::<byte>(value)
|
Information::new::<byte>(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.
|
/// Sample standard deviation, using an already computed mean.
|
||||||
pub fn standard_deviation<Q: RawValue>(values: &[Q], mean: Q) -> Q {
|
pub fn standard_deviation<Q: UnsafeRawValue>(values: &[Q], mean: Q) -> Q {
|
||||||
let mean = mean.raw_value();
|
let mean = mean.unsafe_raw_value();
|
||||||
assert!(
|
assert!(
|
||||||
values.len() > 1,
|
values.len() > 1,
|
||||||
"standard deviation requires at least two measurements"
|
"standard deviation requires at least two measurements"
|
||||||
);
|
);
|
||||||
let sum = values
|
let sum = values
|
||||||
.iter()
|
.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);
|
.fold(0.0, |sum, deviation| sum + deviation);
|
||||||
assert!(sum >= 0.0, "invalid sum of squared deviations");
|
assert!(sum >= 0.0, "invalid sum of squared deviations");
|
||||||
|
|
||||||
// Preserve the operation order of statistical 1.0: dividing by n - 1
|
// Preserve the operation order of statistical 1.0: dividing by n - 1
|
||||||
// before taking the square root also preserves exported floating-point values.
|
// 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)]
|
#[cfg(test)]
|
||||||
|
|||||||
Reference in new issue
Block a user