fix: timers on Linux
On Linux the clock() function measures cpu time instead of wall time. This change uses the Apple code path for Linux.
This commit is contained in:
parent
c325131503
commit
4880a9d2f4
13
timer.c
13
timer.c
@ -1,6 +1,12 @@
|
||||
#include "timer.h"
|
||||
|
||||
#if __APPLE__
|
||||
#ifdef __linux__
|
||||
// Defines strict posix compliance for CLOCK_MONOTONIC
|
||||
#define _POSIX_C_SOURCE 199309L
|
||||
#include <time.h>
|
||||
#endif
|
||||
|
||||
#if __APPLE__ || __linux__
|
||||
#include <sys/time.h>
|
||||
static struct timespec start = {0, 0};
|
||||
|
||||
@ -21,7 +27,8 @@ double stopTimer()
|
||||
|
||||
double measuredSeconds = (double)delta_us / 1000000.;
|
||||
|
||||
if(start.tv_nsec > 0) {
|
||||
if (start.tv_nsec > 0)
|
||||
{
|
||||
start.tv_nsec = 0;
|
||||
start.tv_sec = 0;
|
||||
}
|
||||
@ -45,7 +52,7 @@ double stopTimer()
|
||||
{
|
||||
double measuredSeconds = (clock() - (double)startClocks) / CLOCKS_PER_SEC;
|
||||
|
||||
if(startClocks > 0)
|
||||
if (startClocks > 0)
|
||||
startClocks = 0;
|
||||
else
|
||||
measuredSeconds = -1;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user