Skip to content
Myr

Minor change

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 c64e69f · Browse files · 2 files+10 added−10 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+10 added−10 removed

  • other:+10 added−10 removed

2 files+10 added−10 removed

modified:src/benchmark/measurement.rs+1 added-1 removed
76 unmodified lines
7778 if times.len() < 2 {79 None80 } else {81 Some(standard_deviation(&times))81 Some(standard_deviation(times))82 }83 }8485 /// The median wall clock time
37 unmodified lines
modified:src/quantity/statistics.rs+9 added-9 removed
83 unmodified lines
84 values[len / 2]85 }86}8788fn standard_deviation_f64(values: &[f64]) -> f64 {89 let mean_value = mean(values.iter().copied());88fn standard_deviation_f64(values: impl IntoIterator<Item = f64> + Clone) -> f64 {89 let mean_value = mean(values.clone());9091 let mut squared_deviations = 0.;92 let mut count = 0;92 let mut n = 0;93 for value in values {94 let deviation = value - mean_value;95 squared_deviations += deviation * deviation;96 count += 1;96 n += 1;97 }9899 (1. / ((count - 1) as f64) * squared_deviations).sqrt()99 (1. / ((n - 1) as f64) * squared_deviations).sqrt()100}101102pub fn standard_deviation<Q: UnsafeRawValue>(values: &[Q]) -> Q {103 let values: Vec<_> = values.iter().map(|q| q.unsafe_raw_value()).collect();104 let result = standard_deviation_f64(&values);102pub fn standard_deviation<Q: UnsafeRawValue>(values: impl IntoIterator<Item = Q> + Clone) -> Q {103 let values: Vec<_> = values.into_iter().map(|q| q.unsafe_raw_value()).collect();104 let result = standard_deviation_f64(values);105 Q::unsafe_from_raw_value(result)106}107108/// Compute modifized Z-scores for a given sample. A (unmodified) Z-score is defined by
108 unmodified lines
217 Time::new::<millisecond>(100.0),218 Time::new::<millisecond>(200.0),219 Time::new::<microsecond>(300_000.0),220 ];221 let result = standard_deviation(&values);221 let result = standard_deviation(values);222 assert_relative_eq!(result.get::<millisecond>(), 100.0);223 }224}