show average fps on console

This commit is contained in:
Michael Sippel 2024-07-31 19:18:00 +02:00
parent f8148462d2
commit 17de5bcb76
Signed by: senvas
GPG key ID: 060F22F65102F95C

View file

@ -111,6 +111,9 @@ async fn main() {
let mut last_tap = std::time::Instant::now();
let mut z = 0;
let mut frame_count = 0;
let mut fps_sum_window = std::time::Instant::now();
let mut active = false;
for i in 0..5 {
@ -119,9 +122,18 @@ async fn main() {
event_loop.run(move |event, elwt| {
let tcur = std::time::Instant::now();
if (tcur - fps_sum_window).as_millis() > 5000 {
let avg_fps = (1000.0 * frame_count as f32) / ((tcur - fps_sum_window).as_millis() as f32);
eprintln!("avg fps: {}", avg_fps);
fps_sum_window = tcur;
frame_count = 0;
} else {
frame_count += 1;
}
elwt.set_control_flow(ControlFlow::
WaitUntil(
tcur + Duration::from_millis(100)
tcur + Duration::from_millis(25)
));
inputs.write().unwrap().t = tcur - tbegin;
inputs.write().unwrap().transition_time = tcur - transition_begin;