mirror of
https://github.com/servo/servo.git
synced 2025-08-07 14:35:33 +01:00
Add test for Profiler::get_statistics, and remove empty space around Profiler::get_statistics.
Profiler::get_statistics calculates mean, median, min, and max for a given vector of data. This commit adds a test for the calculated statistics.
This commit is contained in:
parent
6230911330
commit
d47b769cf7
2 changed files with 22 additions and 3 deletions
|
@ -327,8 +327,7 @@ impl Profiler {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_statistics(data: &[f64]) -> (f64, f64, f64, f64) {
|
||||||
fn get_statistics(data: &[f64]) -> (f64, f64, f64, f64) {
|
|
||||||
let data_len = data.len();
|
let data_len = data.len();
|
||||||
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),
|
||||||
|
@ -338,7 +337,6 @@ impl Profiler {
|
||||||
(mean, median, min, max)
|
(mean, median, min, max)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn print_buckets(&mut self) {
|
fn print_buckets(&mut self) {
|
||||||
match self.output {
|
match self.output {
|
||||||
Some(OutputOptions::FileName(ref filename)) => {
|
Some(OutputOptions::FileName(ref filename)) => {
|
||||||
|
|
|
@ -15,3 +15,24 @@ fn time_profiler_smoke_test() {
|
||||||
chan.send(ProfilerMsg::Exit(ipcchan));
|
chan.send(ProfilerMsg::Exit(ipcchan));
|
||||||
assert!(true, "Can tell the profiler thread to exit");
|
assert!(true, "Can tell the profiler thread to exit");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn time_profilers_stats_test() {
|
||||||
|
let even_data = vec![1.234, 3.24567, 3.54578, 5.0, 5.324, 7.345, \
|
||||||
|
9.2345, 10.2342345, 13.2599, 15.0];
|
||||||
|
let (even_mean, even_median, even_min, even_max) = time::Profiler::get_statistics(&even_data);
|
||||||
|
|
||||||
|
assert_eq!(7.34230845, even_mean);
|
||||||
|
assert_eq!(7.345, even_median);
|
||||||
|
assert_eq!(1.234, even_min);
|
||||||
|
assert_eq!(15.0, even_max);
|
||||||
|
|
||||||
|
let odd_data = vec![1.234, 3.24567, 3.54578, 5.0, 5.324, 7.345, \
|
||||||
|
9.2345, 10.2342345, 13.2599];
|
||||||
|
let (odd_mean, odd_median, odd_min, odd_max) = time::Profiler::get_statistics(&odd_data);
|
||||||
|
|
||||||
|
assert_eq!(6.491453833333334, odd_mean);
|
||||||
|
assert_eq!(5.324, odd_median);
|
||||||
|
assert_eq!(1.234, odd_min);
|
||||||
|
assert_eq!(13.2599, odd_max);
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue