pub struct FrameStats { /* private fields */ }Expand description
A rolling window of frame intervals, and the numbers read off it.
Fed from the frame clock’s render delta — the wall-clock time between the
last two updates — so every number below traces to one measurement the
engine already takes.
§FPS is the reciprocal of the mean, not the mean of the reciprocals
Given frames of 10 ms and 30 ms, the mean of 1/dt is (100 + 33.3)/2 = 67
FPS, which is faster than either frame. The window actually took 40 ms and
contained 2 frames, so it ran at 50 FPS, which is what
FrameStats::fps reports: count / total. The two agree only when every
frame is the same length, and they disagree in exactly the case a profiler
exists for.
Implementations§
Source§impl FrameStats
impl FrameStats
Sourcepub fn new() -> Self
pub fn new() -> Self
A window of DEFAULT_FRAME_WINDOW frames.
Sourcepub fn with_window(window: usize) -> Self
pub fn with_window(window: usize) -> Self
A window of window frames, clamped to at least one.
Sourcepub fn record(&mut self, dt: Duration)
pub fn record(&mut self, dt: Duration)
Records one frame interval, evicting the oldest when the window is full.
A zero-length interval is not a frame and is dropped.
FrameClock::update reports Duration::ZERO twice: on the very first
update, which has no previous timestamp to subtract, and on any update
whose timestamp went backwards. Neither is a frame that took no time, and
keeping them would report a frame rate that never happened.
Sourcepub fn fps(&self) -> f64
pub fn fps(&self) -> f64
Frames per second over the window: frames divided by the time they took.
Zero while the window is empty, and zero if the window somehow covers no time at all — an infinite frame rate is not a more honest answer.
Trait Implementations§
Source§impl Clone for FrameStats
impl Clone for FrameStats
Source§impl Debug for FrameStats
impl Debug for FrameStats
Source§impl DebugModule for FrameStats
impl DebugModule for FrameStats
Source§fn debug_section(&self, out: &mut DebugSection)
fn debug_section(&self, out: &mut DebugSection)
out.