From 02a222f435e6a97253522fb0f9f5e0e888842f69 Mon Sep 17 00:00:00 2001 From: Arman Uguray Date: Thu, 16 Mar 2023 09:27:30 -0700 Subject: [PATCH] [frame_stats] Reduce stats time delta between elapsed() and next frame start time This does not account for the time spent in processing `Stats::add_sample` but it should be very close. --- examples/with_winit/src/lib.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/with_winit/src/lib.rs b/examples/with_winit/src/lib.rs index 79601b9..5e023e6 100644 --- a/examples/with_winit/src/lib.rs +++ b/examples/with_winit/src/lib.rs @@ -368,10 +368,11 @@ fn run( surface_texture.present(); device_handle.device.poll(wgpu::Maintain::Poll); + let new_time = Instant::now(); stats.add_sample(stats::Sample { - frame_time_us: frame_start_time.elapsed().as_micros() as u64, + frame_time_us: (new_time - frame_start_time).as_micros() as u64, }); - frame_start_time = Instant::now(); + frame_start_time = new_time; } Event::UserEvent(event) => match event { #[cfg(not(any(target_arch = "wasm32", target_os = "android")))]