From 9191fbce9f4d161e4f871231469ef009c86f177f Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Tue, 12 Feb 2013 21:43:27 -0800 Subject: gras: working on block stats --- include/gras/chrono.hpp | 81 ++++++++++++++++++++++++------------------------- 1 file changed, 39 insertions(+), 42 deletions(-) (limited to 'include') diff --git a/include/gras/chrono.hpp b/include/gras/chrono.hpp index dc013cc..c976675 100644 --- a/include/gras/chrono.hpp +++ b/include/gras/chrono.hpp @@ -3,72 +3,69 @@ //Boost chrono has awesome high res timer! //But its only in very recent boosts, //so we have this little wrapper... +//now/tps inspired by libnumanuma. #ifndef INCLUDED_GRAS_CHRONO_HPP #define INCLUDED_GRAS_CHRONO_HPP #include -#include - -#if BOOST_VERSION >= 104700 -#include namespace gras { + typedef long long time_ticks_t; -namespace chrono -{ - -typedef boost::chrono::time_point TimePoint; -typedef boost::chrono::nanoseconds Duration; + //! Get the time now in tick counts + time_ticks_t time_now(void); -GRAS_FORCE_INLINE TimePoint high_res_now(void) -{ - return boost::posix_time::microsec_clock::universal_time(); + //! Get the number of ticks per second + time_ticks_t time_tps(void); } -GRAS_FORCE_INLINE long long duration_to_ticks(const Duration &d) -{ - return d.count(); -} +//--------------------------------------------------------------------// +//------------------ implementation details below --------------------// +//--------------------------------------------------------------------// -GRAS_FORCE_INLINE unsigned long long tps(void) -{ - return (unsigned long long)(1e9); -} - -} //namespace chrono - -} //namespace gras +#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) -#else -#include +#include namespace gras { -namespace chrono -{ + GRAS_FORCE_INLINE time_ticks_t time_now(void) + { + LARGE_INTEGER counts; + QueryPerformanceCounter(&counts); + return counts.QuadPart; + } -typedef boost::posix_time::ptime TimePoint; -typedef boost::posix_time::time_duration Duration; + GRAS_FORCE_INLINE time_ticks_t time_tps(void) + { + LARGE_INTEGER freq; + QueryPerformanceFrequency(&freq); + return freq.QuadPart; + } -GRAS_FORCE_INLINE TimePoint high_res_now(void) -{ - return boost::posix_time::microsec_clock::universal_time(); -} +} //namespace gras -GRAS_FORCE_INLINE long long duration_to_ticks(const Duration &d) -{ - return d.ticks(); -} +#else + +#include -GRAS_FORCE_INLINE unsigned long long tps(void) +namespace gras { - return boost::posix_time::time_duration::ticks_per_second(); -} -} //namespace chrono + GRAS_FORCE_INLINE time_ticks_t time_now(void) + { + struct timespec ts; + clock_gettime(CLOCK_MONOTONIC, &ts); + return ts.tv_sec*1000000000UL + ts.tv_nsec; + } + + GRAS_FORCE_INLINE time_ticks_t time_tps(void) + { + return 1000000000UL; + } } //namespace gras -- cgit