Add file missing from earlier commit

This commit is contained in:
Matthew Gordon 2025-06-12 10:53:32 -03:00
parent 0d98b4016c
commit 04aec9231b
1 changed files with 31 additions and 0 deletions

View File

@ -0,0 +1,31 @@
use log::info;
pub struct StatisticsReporter {
total_time_seconds: f64,
frame_count: u32,
}
impl StatisticsReporter {
pub fn new() -> Self {
let total_time_seconds = 0.0;
let frame_count = 0;
Self {
total_time_seconds,
frame_count,
}
}
pub fn log_frame_time_seconds(&mut self, t: f64) {
self.total_time_seconds += t;
self.frame_count += 1;
if self.total_time_seconds >= 1.0 {
info!(
"Average frame time: {:.0} ms ({:.1} fps)",
self.total_time_seconds * 1000.0 / (self.frame_count as f64),
(self.frame_count as f64) / self.total_time_seconds
);
self.total_time_seconds = 0.0;
self.frame_count = 0;
}
}
}