2016-09-05 19:47:26 +00:00
|
|
|
/**
|
|
|
|
* Authors.....: Jens Steube <jens.steube@gmail.com>
|
|
|
|
* License.....: MIT
|
|
|
|
*/
|
|
|
|
|
2016-09-06 16:44:05 +00:00
|
|
|
#ifndef _TIMER_H
|
|
|
|
#define _TIMER_H
|
2016-09-05 19:47:26 +00:00
|
|
|
|
2016-09-07 20:29:57 +00:00
|
|
|
#if defined (_POSIX)
|
2016-09-05 19:47:26 +00:00
|
|
|
#include <sys/time.h>
|
|
|
|
#else
|
|
|
|
#endif
|
|
|
|
|
2016-09-07 20:29:57 +00:00
|
|
|
#if defined (_WIN)
|
2016-09-05 19:47:26 +00:00
|
|
|
typedef LARGE_INTEGER hc_timer_t;
|
2016-09-07 20:29:57 +00:00
|
|
|
#elif defined (_POSIX)
|
2016-09-05 19:47:26 +00:00
|
|
|
typedef struct timeval hc_timer_t;
|
|
|
|
#endif
|
|
|
|
|
2016-09-07 20:29:57 +00:00
|
|
|
#if defined (_WIN)
|
2016-09-05 19:47:26 +00:00
|
|
|
|
|
|
|
#define hc_timer_get(a,r) { hc_timer_t hr_freq; QueryPerformanceFrequency (&hr_freq); hc_timer_t hr_tmp; hc_timer_set (&hr_tmp); (r) = (double) ((double) (hr_tmp.QuadPart - (a).QuadPart) / (double) (hr_freq.QuadPart / 1000)); }
|
|
|
|
#define hc_timer_set(a) { QueryPerformanceCounter ((a)); }
|
|
|
|
|
2016-09-07 20:29:57 +00:00
|
|
|
#elif defined (_POSIX)
|
2016-09-05 19:47:26 +00:00
|
|
|
|
|
|
|
#define hc_timer_get(a,r) { hc_timer_t hr_tmp; hc_timer_set (&hr_tmp); (r) = (double) (((hr_tmp.tv_sec - (a).tv_sec) * 1000) + ((double) (hr_tmp.tv_usec - (a).tv_usec) / 1000)); }
|
|
|
|
#define hc_timer_set(a) { gettimeofday ((a), NULL); }
|
|
|
|
|
|
|
|
#endif
|
2016-09-06 16:44:05 +00:00
|
|
|
|
|
|
|
#endif // _TIMER_H
|