1//! Measurement statistics.
2
3use crate::{
4 alloc::{AllocOpMap, AllocTally},
5 counter::{KnownCounterKind, MaxCountUInt},
6 time::FineDuration,
7};
8
9mod sample;
10
11pub(crate) use sample::*;
12
13/// Statistics from samples.
14pub(crate) struct Stats {
15 /// Total number of samples taken.
16 pub sample_count: u32,
17
18 /// Total number of iterations (currently `sample_count * `sample_size`).
19 pub iter_count: u64,
20
21 /// Timing statistics.
22 pub time: StatsSet<FineDuration>,
23
24 /// Maximum allocated bytes and maximum number of allocations associated
25 /// with the corresponding samples for `time`.
26 pub max_alloc: AllocTally<StatsSet<f64>>,
27
28 /// Allocation statistics associated with the corresponding samples for
29 /// `time`.
30 pub alloc_tallies: AllocOpMap<AllocTally<StatsSet<f64>>>,
31
32 /// `Counter` counts associated with the corresponding samples for `time`.
33 pub counts: [Option<StatsSet<MaxCountUInt>>; KnownCounterKind::COUNT],
34}
35
36impl Stats {
37 pub fn get_counts(&self, counter_kind: KnownCounterKind) -> Option<&StatsSet<MaxCountUInt>> {
38 self.counts[counter_kind as usize].as_ref()
39 }
40}
41
42#[derive(Debug)]
43pub(crate) struct StatsSet<T> {
44 /// Associated with minimum amount of time taken by an iteration.
45 pub fastest: T,
46
47 /// Associated with maximum amount of time taken by an iteration.
48 pub slowest: T,
49
50 /// Associated with midpoint time taken by an iteration.
51 pub median: T,
52
53 /// Associated with average time taken by all iterations.
54 pub mean: T,
55}
56
57impl StatsSet<f64> {
58 pub fn is_zero(&self) -> bool {
59 self.fastest == 0.0 && self.slowest == 0.0 && self.median == 0.0 && self.mean == 0.0
60 }
61}
62