Compare commits

..

No commits in common. "bugfix/timer" and "main" have entirely different histories.

13
timer.c
View File

@ -1,12 +1,6 @@
#include "timer.h" #include "timer.h"
#ifdef __linux__ #if __APPLE__
// Defines strict posix compliance for CLOCK_MONOTONIC
#define _POSIX_C_SOURCE 199309L
#include <time.h>
#endif
#if __APPLE__ || __linux__
#include <sys/time.h> #include <sys/time.h>
static struct timespec start = {0, 0}; static struct timespec start = {0, 0};
@ -27,8 +21,7 @@ double stopTimer()
double measuredSeconds = (double)delta_us / 1000000.; double measuredSeconds = (double)delta_us / 1000000.;
if (start.tv_nsec > 0) if(start.tv_nsec > 0) {
{
start.tv_nsec = 0; start.tv_nsec = 0;
start.tv_sec = 0; start.tv_sec = 0;
} }
@ -52,7 +45,7 @@ double stopTimer()
{ {
double measuredSeconds = (clock() - (double)startClocks) / CLOCKS_PER_SEC; double measuredSeconds = (clock() - (double)startClocks) / CLOCKS_PER_SEC;
if (startClocks > 0) if(startClocks > 0)
startClocks = 0; startClocks = 0;
else else
measuredSeconds = -1; measuredSeconds = -1;