fix: use clock instead of timeofday

This commit is contained in:
2026-05-16 18:09:06 +02:00
parent 988cf799b4
commit 3b6d4d642d
4 changed files with 12 additions and 21 deletions
+5 -7
View File
@@ -1,4 +1,4 @@
#include <sys/time.h>
#include <time.h>
#include "types.h"
@@ -7,8 +7,7 @@
void timer_init(Timer *timer, const unsigned int target) {
timer->counter = 0;
timer->target = target;
gettimeofday(&timer->start, NULL);
timer->start = clock();
}
bool timer_inc(Timer *timer) {
@@ -17,14 +16,13 @@ bool timer_inc(Timer *timer) {
}
double timer_reset(Timer *timer) {
struct timeval stop;
clock_t stop;
double secs;
double per_secs;
gettimeofday(&stop, NULL);
stop = clock();
secs = (double)(stop.tv_usec - timer->start.tv_usec) / 1000000 +
(double)(stop.tv_sec - timer->start.tv_sec);
secs = (double)(stop - timer->start) / CLOCKS_PER_SEC;
per_secs = (double)timer->counter / secs;
timer->start = stop;