aboutsummaryrefslogtreecommitdiffstats
path: root/components
diff options
context:
space:
mode:
authorMalisa Smith <malisa.tsmith@gmail.com>2016-07-07 12:59:16 -0700
committerMalisa Smith <malisa.tsmith@gmail.com>2016-07-07 12:59:16 -0700
commit7dccf09ff6800c7da2e50bcccc663f39bdec369f (patch)
treede48c4a4cc166a08aacd0c1bbf2e0a59d53e78ac /components
parentd47b769cf7734b20cc36e6b310359e25d43e0b3d (diff)
downloadservo-7dccf09ff6800c7da2e50bcccc663f39bdec369f.tar.gz
servo-7dccf09ff6800c7da2e50bcccc663f39bdec369f.zip
added test and assertion that profiler statistics data must be sorted
Diffstat (limited to 'components')
-rw-r--r--components/profile/time.rs17
1 files changed, 11 insertions, 6 deletions
diff --git a/components/profile/time.rs b/components/profile/time.rs
index 4659178b506..76ac26497e9 100644
--- a/components/profile/time.rs
+++ b/components/profile/time.rs
@@ -328,12 +328,17 @@ impl Profiler {
}
pub fn get_statistics(data: &[f64]) -> (f64, f64, f64, f64) {
- let data_len = data.len();
- let (mean, median, min, max) =
- (data.iter().sum::<f64>() / (data_len as f64),
- data[data_len / 2],
- data.iter().fold(f64::INFINITY, |a, &b| a.min(b)),
- data.iter().fold(-f64::INFINITY, |a, &b| a.max(b)));
+ data.iter().fold(-f64::INFINITY, |a, &b| {
+ debug_assert!(a < b, "Data must be sorted");
+ b
+ });
+
+ let data_len = data.len();
+ let (mean, median, min, max) =
+ (data.iter().sum::<f64>() / (data_len as f64),
+ data[data_len / 2],
+ data.iter().fold(f64::INFINITY, |a, &b| a.min(b)),
+ data.iter().fold(-f64::INFINITY, |a, &b| a.max(b)));
(mean, median, min, max)
}