simplifying min and max calculation for profiler get_statistics function

This commit is contained in:
Malisa Smith 2016-07-07 13:08:20 -07:00
parent 7dccf09ff6
commit e1092b8b1d
2 changed files with 4 additions and 3 deletions

View file

@ -334,11 +334,12 @@ impl Profiler {
}); });
let data_len = data.len(); let data_len = data.len();
debug_assert!(data_len > 0);
let (mean, median, min, max) = let (mean, median, min, max) =
(data.iter().sum::<f64>() / (data_len as f64), (data.iter().sum::<f64>() / (data_len as f64),
data[data_len / 2], data[data_len / 2],
data.iter().fold(f64::INFINITY, |a, &b| a.min(b)), data[0],
data.iter().fold(-f64::INFINITY, |a, &b| a.max(b))); data[data_len-1]);
(mean, median, min, max) (mean, median, min, max)
} }

View file

@ -37,7 +37,7 @@ fn time_profiler_stats_test() {
assert_eq!(13.2599, odd_max); assert_eq!(13.2599, odd_max);
} }
#[cfg(debug)] #[cfg(debug_assertions)]
#[test] #[test]
#[should_panic] #[should_panic]
fn time_profiler_unsorted_stats_test() { fn time_profiler_unsorted_stats_test() {