From 27f7216be77c4f321e78d02cf09637dddda4e242 Mon Sep 17 00:00:00 2001 From: Ralph Sennhauser Date: Sun, 20 Jul 2025 17:33:07 +0200 Subject: [PATCH] Use proper units for time conversion On *nix the conversion of timeval and timespec to double needs to use the actual unit in use instead of the unrelated clock resolution. Fixes: aa3bd0851393940c0a4a3a7fbc84adec80143160 Fixes: #8215 Signed-off-by: Ralph Sennhauser --- source/lib/timer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/lib/timer.cpp b/source/lib/timer.cpp index 2bde3bd8ad..81fba01a68 100644 --- a/source/lib/timer.cpp +++ b/source/lib/timer.cpp @@ -140,12 +140,12 @@ double timer_Time() ENSURE(start.tv_sec || start.tv_nsec); // must have called timer_LatchStartTime first struct timespec cur; ENSURE(clock_gettime(CLOCK_MONOTONIC, &cur) == 0); - t = (cur.tv_sec - start.tv_sec) + (cur.tv_nsec - start.tv_nsec) * resolution; + t = (cur.tv_sec - start.tv_sec) + (cur.tv_nsec - start.tv_nsec) * 1e-9; #elif HAVE_GETTIMEOFDAY ENSURE(start.tv_sec || start.tv_usec); // must have called timer_LatchStartTime first struct timeval cur; ENSURE(gettimeofday(&cur, 0) == 0); - t = (cur.tv_sec - start.tv_sec) + (cur.tv_usec - start.tv_usec) * resolution; + t = (cur.tv_sec - start.tv_sec) + (cur.tv_usec - start.tv_usec) * 1e-6; #else # error "timer_Time: add timer implementation for this platform!" #endif