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: aa3bd08513
Fixes: #8215
Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
This commit is contained in:
Ralph Sennhauser
2025-07-20 17:33:07 +02:00
parent 70b8c6eb52
commit 27f7216be7
+2 -2
View File
@@ -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