Measuring Framerate
Code#
var deltaTime = loop.IterateOnce().AsDeltaTime();
window.SetTitle(
$"FPS: {loop.FramesPerSecondRecentAverage:N0} avg | " +
$"[{loop.FramesPerSecondRecentMin:N0} - {loop.FramesPerSecondRecentMax:N0}] range | " +
$"{loop.FramesPerSecondLatest:N0} current"
);
Explanation#
The snippet above demonstrates using the reported FPS (frames-per-second) metrics on an ApplicationLoop to set a window's title each frame.
The loop exposes the following properties:
-
FramesPerSecondRecentAverage -
Returns the average framerate of the most recent N frames.
-
FramesPerSecondRecentMin -
Returns the lowest recorded framerate of the most recent N frames.
-
FramesPerSecondRecentMax -
Returns the highest recorded framerate of the most recent N frames.
-
FramesPerSecondLatest -
Returns the framerate of the most recent frame.
Setting the Framerate Buffer Size#
The framerate buffer size (e.g. "N" in the property examples above) can be set by supplying a custom LocalApplicationLoopBuilderConfig object when creating a LocalTinyFfrFactory at initialization-time.