21 #ifndef INCLUDED_GRUEL_HIGH_RES_TIMER_H
22 #define INCLUDED_GRUEL_HIGH_RES_TIMER_H
42 #if defined(linux) || defined(__linux) || defined(__linux__)
43 #define GRUEL_HRT_USE_CLOCK_GETTIME
44 #elif defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
45 #define GRUEL_HRT_USE_QUERY_PERFORMANCE_COUNTER
46 #elif defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__)
47 #define GRUEL_HRT_USE_MACH_ABSOLUTE_TIME
48 #elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
49 #define GRUEL_HRT_USE_MACH_ABSOLUTE_TIME
51 #define GRUEL_HRT_USE_MICROSEC_CLOCK
55 #ifdef GRUEL_HRT_USE_CLOCK_GETTIME
60 clock_gettime(CLOCK_MONOTONIC, &ts);
70 #ifdef GRUEL_HRT_USE_MACH_ABSOLUTE_TIME
71 #include <mach/mach_time.h>
74 return mach_absolute_time();
78 mach_timebase_info_data_t info;
79 mach_timebase_info(&info);
85 #ifdef GRUEL_HRT_USE_QUERY_PERFORMANCE_COUNTER
90 QueryPerformanceCounter(&counts);
91 return counts.QuadPart;
96 QueryPerformanceFrequency(&freq);
102 #ifdef GRUEL_HRT_USE_MICROSEC_CLOCK
103 #include <boost/date_time/posix_time/posix_time.hpp>
106 static const boost::posix_time::ptime epoch(boost::posix_time::from_time_t(0));
107 return (boost::posix_time::microsec_clock::universal_time() - epoch).ticks();
111 return boost::posix_time::time_duration::ticks_per_second();
116 #include <boost/date_time/posix_time/posix_time.hpp>
119 static const double hrt_ticks_per_utc_ticks =
gruel::high_res_timer_tps()/double(boost::posix_time::time_duration::ticks_per_second());
120 boost::posix_time::time_duration utc = boost::posix_time::microsec_clock::universal_time() - boost::posix_time::from_time_t(0);