From f436f3266b216c04a8e3b1b1e5b2bf2c54b99ece Mon Sep 17 00:00:00 2001 From: Aciz Date: Sun, 11 Aug 2024 22:49:23 +0300 Subject: [PATCH] Optimize optimal frame calculation No need to iterate all frames, we can exit as soon as we hit a frametime that is higher than desired as we are iterating over the sorted array --- src/client/cl_main.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/client/cl_main.c b/src/client/cl_main.c index 08be5a7a..6666764d 100644 --- a/src/client/cl_main.c +++ b/src/client/cl_main.c @@ -849,9 +849,11 @@ static void CL_TimedemoResults(void) { numOptimalFrames = 0; for (i = 0; i < numFrames; i++) { - if (sortedFrametimes[i] / 1000.0f <= desiredFrametime) { - numOptimalFrames++; + if (sortedFrametimes[i] / 1000.0f > desiredFrametime) { + break; } + + numOptimalFrames++; } Com_Printf("\n----- Benchmark results -----\n");