From 2f1e37bb7cad2284f52dcef1377e9eebbabc35d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Mon, 12 Jan 2026 14:29:49 +0800 Subject: [PATCH] Common (Windows): improves performance of `ffTimeGetTick` --- src/common/impl/time.c | 4 ++++ src/common/time.h | 11 ++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/common/impl/time.c b/src/common/impl/time.c index b49dd0aee..40bd9b6ff 100644 --- a/src/common/impl/time.c +++ b/src/common/impl/time.c @@ -81,3 +81,7 @@ FFTimeGetAgeResult ffTimeGetAge(uint64_t birthMs, uint64_t nowMs) return result; } + +#ifdef _WIN32 + double ffQpcMultiplier; +#endif diff --git a/src/common/time.h b/src/common/time.h index cdb345d3c..867980f12 100644 --- a/src/common/time.h +++ b/src/common/time.h @@ -15,11 +15,16 @@ static inline double ffTimeGetTick(void) //In msec { #ifdef _WIN32 - LARGE_INTEGER frequency; - QueryPerformanceFrequency(&frequency); + extern double ffQpcMultiplier; + if (ffQpcMultiplier == 0) + { + LARGE_INTEGER frequency; + QueryPerformanceFrequency(&frequency); + ffQpcMultiplier = 1000. / (double) frequency.QuadPart; + } LARGE_INTEGER start; QueryPerformanceCounter(&start); - return (double) start.QuadPart * 1000 / (double) frequency.QuadPart; + return (double) start.QuadPart * ffQpcMultiplier; #elif defined(__HAIKU__) return (double) system_time() / 1000.; #else