radiate_rust/engines/schema/
timer.rs1use std::time::Instant;
2
3pub struct Timer {
4 start: Instant,
5 end: Instant,
6 stopped: bool,
7}
8
9impl Timer {
10 pub fn new() -> Timer {
11 Timer {
12 start: Instant::now(),
13 end: Instant::now(),
14 stopped: false,
15 }
16 }
17
18 #[allow(dead_code)]
19 pub fn start(&mut self) {
20 self.start = Instant::now();
21 self.end = Instant::now();
22 }
23
24 pub fn stop(&mut self) {
25 self.end = Instant::now();
26 self.stopped = true;
27 }
28
29 pub fn elapsed(&self) -> std::time::Duration {
30 if !self.stopped {
31 return self.start.elapsed();
32 }
33
34 self.end.duration_since(self.start)
35 }
36}
37
38impl Clone for Timer {
39 fn clone(&self) -> Self {
40 Timer {
41 start: self.start,
42 end: self.end,
43 stopped: self.stopped,
44 }
45 }
46}