2016-09-05 21:47:26 +02:00
|
|
|
/**
|
|
|
|
* Authors.....: Jens Steube <jens.steube@gmail.com>
|
|
|
|
* License.....: MIT
|
|
|
|
*/
|
|
|
|
|
2016-09-06 18:44:05 +02:00
|
|
|
#ifndef _TIMER_H
|
|
|
|
#define _TIMER_H
|
2016-09-05 21:47:26 +02:00
|
|
|
|
2016-09-07 22:29:57 +02:00
|
|
|
#if defined (_POSIX)
|
2016-09-05 21:47:26 +02:00
|
|
|
#include <sys/time.h>
|
2016-09-11 11:42:19 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined (_WIN)
|
|
|
|
#include <windows.h>
|
2016-09-05 21:47:26 +02:00
|
|
|
#endif
|
|
|
|
|
2016-09-07 22:29:57 +02:00
|
|
|
#if defined (_WIN)
|
2016-09-05 21:47:26 +02:00
|
|
|
typedef LARGE_INTEGER hc_timer_t;
|
2016-09-07 22:29:57 +02:00
|
|
|
#elif defined (_POSIX)
|
2016-09-05 21:47:26 +02:00
|
|
|
typedef struct timeval hc_timer_t;
|
|
|
|
#endif
|
|
|
|
|
2016-09-07 22:29:57 +02:00
|
|
|
#if defined (_WIN)
|
2016-09-05 21:47:26 +02: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 22:29:57 +02:00
|
|
|
#elif defined (_POSIX)
|
2016-09-05 21:47:26 +02: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 18:44:05 +02:00
|
|
|
|
|
|
|
#endif // _TIMER_H
|