- if now - last_report_time > Duration::from_secs(10) {
- let fps = (frame_cnt - last_report_frame_cnt) as f32 /
- (now - last_report_time).as_secs() as f32;
- println!("fps={}", fps);
+ frame_cnt += 1;
+ accum_idle_time += time_before_draw - time_before_swap;
+ accum_draw_time += time_after_draw - time_before_draw;
+ if now - last_report_time > Duration::from_secs(5) {
+ fn millis(d : Duration) -> f32 {
+ d.as_secs() as f32 * 1e3 + d.subsec_nanos() as f32 / 1e6
+ }
+ let frames_done = frame_cnt - last_report_frame_cnt;
+ let fps = frames_done as f32 / (now - last_report_time).as_secs() as f32;
+ let avg_draw_time = millis(accum_draw_time / frames_done);
+ let avg_idle_time = millis(accum_idle_time / frames_done);
+ println!("fps={:.1} draw={:.1}ms idle={:.1}ms", fps, avg_draw_time, avg_idle_time);
+