use super::*;
pub struct LoopTimer {
pub start: Instant,
pub end: Instant,
pub time: Duration,
pub target: Duration,
pub count: u32,
}
impl LoopTimer {
pub fn new(target: Duration) -> Self {
let now = Instant::now();
Self {
count: 0,
start: now,
end: now + target,
time: target,
target
}
}
pub fn new_from(now: Instant, target: Duration) -> Self {
Self {
count: 0,
start: now,
end: now + target,
time: target,
target
}
}
pub fn reset_count(&mut self) {
self.count = 0;
}
pub fn start(&mut self) {
self.start = Instant::now();
}
pub fn end(&mut self) {
self.end = Instant::now();
self.time = self.end.saturating_duration_since(self.end);
self.count += 1;
}
pub fn length(&self) -> u128 {
self.time.as_nanos()
}
}