pub struct Statistics {
pub samples: usize,
pub min_us: f64,
pub p50_us: f64,
pub p90_us: f64,
pub p95_us: f64,
pub p99_us: f64,
pub max_us: f64,
pub mean_us: f64,
pub stddev_us: f64,
}Expand description
The statistics of one set of samples, in microseconds.
Fields§
§samples: usizeHow many samples.
min_us: f64The smallest.
p50_us: f64The median.
p90_us: f64The 90th percentile.
p95_us: f64The 95th percentile.
p99_us: f64The 99th percentile.
max_us: f64The largest.
mean_us: f64The mean.
stddev_us: f64The population standard deviation.
Implementations§
Source§impl Statistics
impl Statistics
Sourcepub fn of(samples: &[Duration]) -> Self
pub fn of(samples: &[Duration]) -> Self
Reduce samples. An empty set is all zeros with samples: 0.
use std::time::Duration;
use majordomus_cli::bench::Statistics;
let s = Statistics::of(&(1..=100).map(Duration::from_micros).collect::<Vec<_>>());
assert_eq!(s.samples, 100);
assert_eq!(s.min_us, 1.0);
assert_eq!(s.max_us, 100.0);
assert_eq!(s.p50_us, 50.0);
assert_eq!(s.p99_us, 99.0);
assert!((s.mean_us - 50.5).abs() < 1e-9);Sourcepub fn samples_at_or_above(&self, metric: &str) -> Option<usize>
pub fn samples_at_or_above(&self, metric: &str) -> Option<usize>
How many samples are certainly at or above a metric’s value: the samples a verdict
on that metric rests on. A nearest-rank percentile of rank r has n - r + 1 samples
at or above it; the maximum has one, the minimum all of them; the mean is an
aggregate of every sample and one outlier can carry it, so it counts as one. None
for a metric this does not know.
A metric over its threshold is a regression only when at least two samples agree: the median of one sample, or the p99 of twenty, is the single slowest sample, which one scheduler hiccup on a loaded runner decides.
use std::time::Duration;
use majordomus_cli::bench::Statistics;
let one = Statistics::of(&[Duration::from_millis(23)]);
assert_eq!(one.samples_at_or_above("p50"), Some(1));
let five = Statistics::of(&vec![Duration::from_millis(9); 5]);
assert_eq!(five.samples_at_or_above("p50"), Some(3));
assert_eq!(five.samples_at_or_above("p99"), Some(1));
assert_eq!(five.samples_at_or_above("min"), Some(5));
assert_eq!(five.samples_at_or_above("mean"), Some(1));
assert_eq!(five.samples_at_or_above("p42"), None);Trait Implementations§
Source§impl Clone for Statistics
impl Clone for Statistics
Source§fn clone(&self) -> Statistics
fn clone(&self) -> Statistics
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for Statistics
impl Debug for Statistics
Source§impl<'de> Deserialize<'de> for Statistics
impl<'de> Deserialize<'de> for Statistics
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl JsonSchema for Statistics
impl JsonSchema for Statistics
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
$ref keyword. Read moreSource§impl PartialEq for Statistics
impl PartialEq for Statistics
Source§fn eq(&self, other: &Statistics) -> bool
fn eq(&self, other: &Statistics) -> bool
self and other values to be equal, and is used by ==.