summaryrefslogtreecommitdiff
path: root/include/gras/chrono.hpp
diff options
context:
space:
mode:
authorJosh Blum2013-02-24 14:29:16 -0800
committerJosh Blum2013-02-24 14:29:16 -0800
commit883743bd59f40f9ce1e30bd196de78c2e7646294 (patch)
treef9b0cf4f0a1d3894643a681a54aa21fe55398243 /include/gras/chrono.hpp
parent6841702911d07a2bad86ecd3bfc243b6a688ad2a (diff)
parentdecd0f40714a71c6fb5c4f100e8f51c6ef238b26 (diff)
downloadsandhi-883743bd59f40f9ce1e30bd196de78c2e7646294.tar.gz
sandhi-883743bd59f40f9ce1e30bd196de78c2e7646294.tar.bz2
sandhi-883743bd59f40f9ce1e30bd196de78c2e7646294.zip
Merge branch 'stats'
Conflicts: grextras include/gras/top_block.hpp lib/block_handlers.cpp lib/block_task.cpp lib/element_impl.hpp tests/CMakeLists.txt
Diffstat (limited to 'include/gras/chrono.hpp')
-rw-r--r--include/gras/chrono.hpp74
1 files changed, 74 insertions, 0 deletions
diff --git a/include/gras/chrono.hpp b/include/gras/chrono.hpp
new file mode 100644
index 0000000..c976675
--- /dev/null
+++ b/include/gras/chrono.hpp
@@ -0,0 +1,74 @@
+// 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...
+//now/tps inspired by libnumanuma.
+
+#ifndef INCLUDED_GRAS_CHRONO_HPP
+#define INCLUDED_GRAS_CHRONO_HPP
+
+#include <gras/gras.hpp>
+
+namespace gras
+{
+ typedef long long time_ticks_t;
+
+ //! Get the time now in tick counts
+ time_ticks_t time_now(void);
+
+ //! Get the number of ticks per second
+ time_ticks_t time_tps(void);
+}
+
+//--------------------------------------------------------------------//
+//------------------ implementation details below --------------------//
+//--------------------------------------------------------------------//
+
+#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
+
+#include <windows.h>
+
+namespace gras
+{
+
+ GRAS_FORCE_INLINE time_ticks_t time_now(void)
+ {
+ LARGE_INTEGER counts;
+ QueryPerformanceCounter(&counts);
+ return counts.QuadPart;
+ }
+
+ GRAS_FORCE_INLINE time_ticks_t time_tps(void)
+ {
+ LARGE_INTEGER freq;
+ QueryPerformanceFrequency(&freq);
+ return freq.QuadPart;
+ }
+
+} //namespace gras
+
+#else
+
+#include <ctime>
+
+namespace gras
+{
+
+ 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
+
+#endif
+
+#endif /*INCLUDED_GRAS_CHRONO_HPP*/