Skip to main content

alux_bench/
sampling.rs

1//! States how thoroughly a suite is sampled.
2
3use core::time::Duration;
4
5/// How many samples one case is measured over, and how long one sample may spend on rounds.
6///
7/// A sample is one call of a case's routine, running the rounds that fit [`Self::spend`], or the
8/// fewest the interpreter can run where no spend is stated.
9#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
10pub struct BenchSampling {
11    samples: usize,
12    spend: Option<Duration>,
13}
14
15impl BenchSampling {
16    /// States that each case is measured over `samples` samples of the fewest rounds.
17    pub const fn new(samples: usize) -> Self {
18        Self { samples, spend: None }
19    }
20
21    /// States that one sample runs the rounds it can run in about `spend`.
22    #[must_use]
23    pub const fn spending(mut self, spend: Duration) -> Self {
24        self.spend = Some(spend);
25
26        self
27    }
28
29    /// Returns how many samples each case is measured over.
30    pub const fn samples(self) -> usize {
31        self.samples
32    }
33
34    /// Returns how long one sample may spend on rounds, or `None` for the fewest rounds.
35    pub const fn spend(self) -> Option<Duration> {
36        self.spend
37    }
38}
39
40impl From<usize> for BenchSampling {
41    fn from(samples: usize) -> Self {
42        Self::new(samples)
43    }
44}