Skip to main content

alux_bench/
case.rs

1//! Names what is measured and how much of it one sample runs.
2
3use core::ops::Range;
4
5/// Names one measured case: the group it is read within, and the subject it measures.
6///
7/// A group holds the cases a run compares, such as one operation under one load. A subject is what
8/// is measured under it, such as one provider.
9#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
10pub struct BenchCase {
11    group: &'static str,
12    subject: &'static str,
13}
14
15impl BenchCase {
16    /// States that `subject` is measured within `group`.
17    pub const fn new(group: &'static str, subject: &'static str) -> Self {
18        Self { group, subject }
19    }
20
21    /// Returns the group the case is read within.
22    pub const fn group(self) -> &'static str {
23        self.group
24    }
25
26    /// Returns the subject the case measures.
27    pub const fn subject(self) -> &'static str {
28        self.subject
29    }
30}
31
32/// How many rounds one sample runs.
33#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
34pub struct BenchRounds(u64);
35
36impl BenchRounds {
37    /// States a sample of `count` rounds.
38    pub const fn new(count: u64) -> Self {
39        Self(count)
40    }
41
42    /// Returns how many rounds the sample runs.
43    pub const fn count(self) -> u64 {
44        self.0
45    }
46}
47
48impl IntoIterator for BenchRounds {
49    type IntoIter = Range<u64>;
50    type Item = u64;
51
52    /// Iterates the rounds, so a routine reads `for _ in rounds`.
53    fn into_iter(self) -> Self::IntoIter {
54        0..self.0
55    }
56}
57
58impl From<u64> for BenchRounds {
59    fn from(count: u64) -> Self {
60        Self::new(count)
61    }
62}