display response time statistics
@@ -49,3 +49,20 @@ pub fn gcd(u: usize, v: usize) -> usize {
};
gcd
}
+
+/// Calculate mean for a vector of f32s.
+pub fn mean(list: &[f32]) -> f32 {
+ let sum: f32 = Iterator::sum(list.iter());
+ f32::from(sum) / (list.len() as f32)
+}
+
+/// Calculate median for a vector of f32s.
+pub fn median(list: &[f32]) -> f32 {
+ let len = list.len();
+ let mid = len / 2;
+ if len % 2 == 0 {
+ mean(&list[(mid - 1)..(mid + 1)])
+ } else {
+ f32::from(list[mid])
+ }
+}
\ No newline at end of file
