Update doble libs. #3
Binary file not shown.
Binary file not shown.
Binary file not shown.
34
timer.c
34
timer.c
@ -1,6 +1,37 @@
|
|||||||
#include <time.h>
|
|
||||||
#include "timer.h"
|
#include "timer.h"
|
||||||
|
|
||||||
|
#if __APPLE__
|
||||||
|
#include <sys/time.h>
|
||||||
|
static struct timespec start = {0, 0};
|
||||||
|
|
||||||
|
// Starts the timer.
|
||||||
|
void startTimer()
|
||||||
|
{
|
||||||
|
clock_gettime(CLOCK_MONOTONIC, &start);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Returns the time in seconds since startTimer() was called.
|
||||||
|
double stopTimer()
|
||||||
|
{
|
||||||
|
struct timespec end;
|
||||||
|
|
||||||
|
clock_gettime(CLOCK_MONOTONIC, &end);
|
||||||
|
|
||||||
|
unsigned long long delta_us = (end.tv_sec - start.tv_sec) * 1000000 + (end.tv_nsec - start.tv_nsec) / 1000;
|
||||||
|
|
||||||
|
double measuredSeconds = (double)delta_us / 1000000.;
|
||||||
|
|
||||||
|
if(start.tv_nsec > 0) {
|
||||||
|
start.tv_nsec = 0;
|
||||||
|
start.tv_sec = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
measuredSeconds = -1;
|
||||||
|
|
||||||
|
return measuredSeconds;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
#include <time.h>
|
||||||
static clock_t startClocks = 0;
|
static clock_t startClocks = 0;
|
||||||
|
|
||||||
// Starts the timer.
|
// Starts the timer.
|
||||||
@ -21,3 +52,4 @@ double stopTimer()
|
|||||||
|
|
||||||
return measuredSeconds;
|
return measuredSeconds;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user