2016-09-11 09:42:19 +00:00
|
|
|
/**
|
2016-09-11 20:20:15 +00:00
|
|
|
* Author......: See docs/credits.txt
|
2016-09-11 09:42:19 +00:00
|
|
|
* License.....: MIT
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "common.h"
|
2016-10-01 10:55:39 +00:00
|
|
|
#include "types.h"
|
2016-09-11 09:42:19 +00:00
|
|
|
#include "timer.h"
|
2016-10-01 10:55:39 +00:00
|
|
|
|
|
|
|
#if defined (_WIN)
|
|
|
|
|
|
|
|
inline void hc_timer_set (hc_timer_t *a)
|
|
|
|
{
|
|
|
|
QueryPerformanceCounter (a);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline double hc_timer_get (hc_timer_t a)
|
|
|
|
{
|
|
|
|
hc_timer_t hr_freq;
|
|
|
|
|
|
|
|
QueryPerformanceFrequency (&hr_freq);
|
|
|
|
|
|
|
|
hc_timer_t hr_tmp;
|
|
|
|
|
|
|
|
hc_timer_set (&hr_tmp);
|
|
|
|
|
2017-12-10 13:02:43 +00:00
|
|
|
double r = ((double) hr_tmp.QuadPart - (double) a.QuadPart) / ((double) hr_freq.QuadPart / 1000);
|
|
|
|
|
|
|
|
return r;
|
2016-10-01 10:55:39 +00:00
|
|
|
}
|
|
|
|
|
2017-02-23 23:55:06 +00:00
|
|
|
#else
|
2016-10-01 10:55:39 +00:00
|
|
|
|
|
|
|
inline void hc_timer_set (hc_timer_t* a)
|
|
|
|
{
|
2017-12-26 13:09:30 +00:00
|
|
|
#if defined(__APPLE__) && defined(MISSING_CLOCK_GETTIME)
|
2018-01-11 01:41:16 +00:00
|
|
|
gettimeofday (a, NULL);
|
2017-12-26 12:49:17 +00:00
|
|
|
#else
|
2017-12-10 13:02:43 +00:00
|
|
|
clock_gettime (CLOCK_MONOTONIC, a);
|
2017-12-26 12:49:17 +00:00
|
|
|
#endif
|
2016-10-01 10:55:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline double hc_timer_get (hc_timer_t a)
|
|
|
|
{
|
|
|
|
hc_timer_t hr_tmp;
|
|
|
|
|
|
|
|
hc_timer_set (&hr_tmp);
|
|
|
|
|
2018-01-11 01:41:16 +00:00
|
|
|
#if defined(__APPLE__) && defined(MISSING_CLOCK_GETTIME)
|
|
|
|
return (double) (((hr_tmp.tv_sec - (a).tv_sec) * 1000) + ((double) (hr_tmp.tv_usec - (a).tv_usec) / 1000));
|
|
|
|
#else
|
2017-12-10 13:02:43 +00:00
|
|
|
hc_timer_t s;
|
|
|
|
|
|
|
|
s.tv_sec = hr_tmp.tv_sec - a.tv_sec;
|
|
|
|
s.tv_nsec = hr_tmp.tv_nsec - a.tv_nsec;
|
|
|
|
|
|
|
|
if (s.tv_nsec < 0)
|
|
|
|
{
|
|
|
|
s.tv_sec -= 1;
|
|
|
|
s.tv_nsec += 1000000000;
|
|
|
|
}
|
|
|
|
|
|
|
|
double r = ((double) s.tv_sec * 1000) + ((double) s.tv_nsec / 1000000);
|
|
|
|
|
|
|
|
return r;
|
2018-01-11 01:41:16 +00:00
|
|
|
#endif
|
2016-10-01 10:55:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|