maplibre/util/
fps_meter.rs1use std::time::Duration;
2
3use instant::Instant;
4
5pub struct FPSMeter {
17 next_report: Instant,
18 frame_count: u32,
19}
20
21impl FPSMeter {
22 pub fn new() -> Self {
23 let start = Instant::now();
24 Self {
25 next_report: start + Duration::from_secs(1),
26 frame_count: 0,
27 }
28 }
29
30 pub fn update_and_print(&mut self) {
31 self.frame_count += 1;
32 let now = Instant::now();
33 if now >= self.next_report {
34 log::warn!("{} FPS", self.frame_count);
35 self.frame_count = 0;
36 self.next_report = now + Duration::from_secs(1);
37 }
38 }
39}
40
41impl Default for FPSMeter {
42 fn default() -> Self {
43 Self::new()
44 }
45}