wgpu_benchmark/
context.rs

1use std::time::Duration;
2
3#[derive(Clone, Copy)]
4pub enum LoopControl {
5    Iterations(u32),
6    Time(Duration),
7}
8
9impl Default for LoopControl {
10    fn default() -> Self {
11        LoopControl::Time(Duration::from_secs(2))
12    }
13}
14
15impl LoopControl {
16    pub(crate) fn finished(&self, iterations: u32, elapsed: Duration) -> bool {
17        match self {
18            LoopControl::Iterations(target) => iterations >= *target,
19            LoopControl::Time(target) => elapsed >= *target,
20        }
21    }
22}
23
24pub struct BenchmarkContext {
25    pub(crate) override_iters: Option<LoopControl>,
26    pub default_iterations: LoopControl,
27    pub(crate) is_test: bool,
28}
29
30impl BenchmarkContext {
31    pub fn is_test(&self) -> bool {
32        self.is_test
33    }
34}