darklua_core/utils/
timer.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use std::time::{Duration, Instant};

#[derive(Debug, Clone, Eq, PartialEq)]
pub struct Timer {
    start: Instant,
    accumulated_time: Duration,
}

impl Timer {
    pub fn now() -> Self {
        Self {
            start: Instant::now(),
            accumulated_time: Duration::new(0, 0),
        }
    }

    pub fn pause(&mut self) {
        let duration = self.start.elapsed();
        self.accumulated_time += duration;
    }

    pub fn start(&mut self) {
        self.start = Instant::now();
    }

    pub fn duration_label(&self) -> String {
        let duration = self.start.elapsed();
        durationfmt::to_string(duration + self.accumulated_time)
    }
}