use std::process::ExitStatus;
use crate::quantity::statistics::{max, mean, median, min, modified_zscores, standard_deviation};
use crate::quantity::{Information, Time};
#[derive(Debug, Default, Copy, Clone, PartialEq)]
pub struct Measurement {
pub time_wall_clock: Time,
pub time_user: Time,
pub time_system: Time,
pub peak_memory_usage: Information,
pub exit_status: ExitStatus,
}
#[derive(Debug, Default, Clone, PartialEq)]
pub struct Measurements {
pub measurements: Vec<Measurement>,
}
impl Measurements {
pub fn new(measurements: Vec<Measurement>) -> Self {
Self { measurements }
}
pub fn len(&self) -> usize {
self.measurements.len()
}
pub fn is_empty(&self) -> bool {
self.measurements.is_empty()
}
pub fn push(&mut self, measurement: Measurement) {
self.measurements.push(measurement);
}
pub fn wall_clock_times(&self) -> impl Iterator<Item = Time> + '_ {
self.measurements.iter().map(|m| m.time_wall_clock)
}
pub fn time_wall_clock_mean(&self) -> Time {
mean(self.wall_clock_times())
}
pub fn stddev(&self) -> Option<Time> {
let times: Vec<_> = self.wall_clock_times().collect();
if times.len() < 2 {
None
} else {
Some(standard_deviation(times))
}
}
pub fn median(&self) -> Time {
median(self.wall_clock_times())
}
pub fn min(&self) -> Time {
min(self.wall_clock_times())
}
pub fn max(&self) -> Time {
max(self.wall_clock_times())
}
pub fn modified_zscores(&self) -> Vec<f64> {
modified_zscores(&self.wall_clock_times().collect::<Vec<_>>())
}
pub fn time_user_mean(&self) -> Time {
mean(self.measurements.iter().map(|m| m.time_user))
}
pub fn time_system_mean(&self) -> Time {
mean(self.measurements.iter().map(|m| m.time_system))
}
pub fn peak_memory_usage_mean(&self) -> Information {
mean(self.measurements.iter().map(|m| m.peak_memory_usage))
}
}