darklua_core/utils/
timer.rs

1use std::time::{Duration, Instant};
2
3#[derive(Debug, Clone, Eq, PartialEq)]
4pub struct Timer {
5    start: Instant,
6    accumulated_time: Duration,
7}
8
9impl Timer {
10    pub fn now() -> Self {
11        Self {
12            start: Instant::now(),
13            accumulated_time: Duration::new(0, 0),
14        }
15    }
16
17    pub fn pause(&mut self) {
18        let duration = self.start.elapsed();
19        self.accumulated_time += duration;
20    }
21
22    pub fn start(&mut self) {
23        self.start = Instant::now();
24    }
25
26    pub fn duration_label(&self) -> String {
27        let duration = self.start.elapsed();
28        durationfmt::to_string(duration + self.accumulated_time)
29    }
30}