summaryrefslogtreecommitdiff
path: root/include/gras/chrono.hpp
diff options
context:
space:
mode:
authorJosh Blum2013-02-11 23:57:01 -0800
committerJosh Blum2013-02-17 20:51:23 -0600
commit93afc6bff6ce58c08d8ae4b1509f682a05a9c59d (patch)
tree51b4326bf88f54fb520f8c55c1a1634edd4dd21e /include/gras/chrono.hpp
parent54b349885289913a212cf2fa88729cb327d0c84a (diff)
downloadsandhi-93afc6bff6ce58c08d8ae4b1509f682a05a9c59d.tar.gz
sandhi-93afc6bff6ce58c08d8ae4b1509f682a05a9c59d.tar.bz2
sandhi-93afc6bff6ce58c08d8ae4b1509f682a05a9c59d.zip
gras: ifdef'd chrono for timing purposes
Diffstat (limited to 'include/gras/chrono.hpp')
-rw-r--r--include/gras/chrono.hpp77
1 files changed, 77 insertions, 0 deletions
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 <gras/gras.hpp>
+#include <boost/version.hpp>
+
+#if BOOST_VERSION >= 104700
+#include <boost/chrono.hpp>
+
+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 <boost/date_time/posix_time/posix_time.hpp>
+
+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*/