From 93afc6bff6ce58c08d8ae4b1509f682a05a9c59d Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Mon, 11 Feb 2013 23:57:01 -0800 Subject: gras: ifdef'd chrono for timing purposes --- include/gras/chrono.hpp | 77 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 include/gras/chrono.hpp (limited to 'include/gras/chrono.hpp') diff --git a/include/gras/chrono.hpp b/include/gras/chrono.hpp new file mode 100644 index 0000000..dc013cc --- /dev/null +++ b/include/gras/chrono.hpp @@ -0,0 +1,77 @@ +// Copyright (C) by Josh Blum. See LICENSE.txt for licensing information. + +//Boost chrono has awesome high res timer! +//But its only in very recent boosts, +//so we have this little wrapper... + +#ifndef INCLUDED_GRAS_CHRONO_HPP +#define INCLUDED_GRAS_CHRONO_HPP + +#include +#include + +#if BOOST_VERSION >= 104700 +#include + +namespace gras +{ + +namespace chrono +{ + +typedef boost::chrono::time_point TimePoint; +typedef boost::chrono::nanoseconds Duration; + +GRAS_FORCE_INLINE TimePoint high_res_now(void) +{ + return boost::posix_time::microsec_clock::universal_time(); +} + +GRAS_FORCE_INLINE long long duration_to_ticks(const Duration &d) +{ + return d.count(); +} + +GRAS_FORCE_INLINE unsigned long long tps(void) +{ + return (unsigned long long)(1e9); +} + +} //namespace chrono + +} //namespace gras + +#else +#include + +namespace gras +{ + +namespace chrono +{ + +typedef boost::posix_time::ptime TimePoint; +typedef boost::posix_time::time_duration Duration; + +GRAS_FORCE_INLINE TimePoint high_res_now(void) +{ + return boost::posix_time::microsec_clock::universal_time(); +} + +GRAS_FORCE_INLINE long long duration_to_ticks(const Duration &d) +{ + return d.ticks(); +} + +GRAS_FORCE_INLINE unsigned long long tps(void) +{ + return boost::posix_time::time_duration::ticks_per_second(); +} + +} //namespace chrono + +} //namespace gras + +#endif + +#endif /*INCLUDED_GRAS_CHRONO_HPP*/ -- cgit