Optimize FPS calculation using precomputed frame timings
This commit streamlines the FPS calculation within the frame times widget by utilizing the precomputed timings_ms
array that already contains the durations between frames in milliseconds. By summing up these precomputed timings, we avoid redundant computation of frame durations from the times_ns
timestamps.
The optimized approach calculates the total frame time directly in milliseconds, determines the average frame time, and then computes the FPS by dividing 1000 ms by the average frame time in milliseconds. This change not only improves the efficiency of the code but also simplifies the logic for calculating the average FPS.
Refactoring:
- Use
timings_ms
instead of recomputing frame durations fromtimes_ns
. - Calculate
total_ms
andavg_frametime_ms
within the FPS update conditional. - Adjust FPS calculation to
1000.f / avg_frametime_ms
.