8 #ifndef MANAK_UTIL_TIMER_HPP_INCLUDED
9 #define MANAK_UTIL_TIMER_HPP_INCLUDED
18 #if defined(__unix__) || defined(__unix)
23 #elif defined(__MACH__) && defined(__APPLE__)
24 #include <mach/mach_time.h>
38 #if !defined(HAVE_UINT64_T)
39 #if SIZEOF_UNSIGNED_LONG == 8
40 typedef unsigned long uint64_t;
42 typedef unsigned long long uint64_t;
43 #endif // SIZEOF_UNSIGNED_LONG
44 #endif // HAVE_UINT64_T
47 #if defined(_MSC_VER) || defined(_MSC_EXTENSIONS)
48 #define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64
50 #define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL
51 #endif // _MSC_VER, _MSC_EXTENSIONS
66 inline void timersub(
const timeval* tvp,
const timeval* uvp, timeval* vvp)
68 vvp->tv_sec = tvp->tv_sec - uvp->tv_sec;
69 vvp->tv_usec = tvp->tv_usec - uvp->tv_usec;
73 vvp->tv_usec += 1000000;
96 #if defined(__unix__) || defined(__unix)
97 gettimeofday (&tv, NULL);
100 static double frequency = 0.0;
101 static LARGE_INTEGER offset;
106 if (frequency == 0.0)
109 if (!QueryPerformanceFrequency(&pF))
116 QueryPerformanceCounter(&offset);
117 frequency = (double)pF.QuadPart / 1000000.0;
121 if (frequency != 0.0)
125 QueryPerformanceCounter(&pC);
127 pC.QuadPart -= offset.QuadPart;
128 double microseconds = (double)pC.QuadPart / frequency;
129 pC.QuadPart = microseconds;
130 tv.tv_sec = (
long)pC.QuadPart / 1000000;
131 tv.tv_usec = (long)(pC.QuadPart % 1000000);
136 return tv.tv_sec * 1000000 + tv.tv_usec;
186 const std::string& from,
187 const std::string& to);
199 #ifndef MANAK_USE_DYN_LINK
201 #endif // MANAK_USE_DYN_LINK
203 #endif // MANAK_UTIL_TIMER_HPP_INCLUDED
static uint64_t & CTime()
Get-set current timing.
static void StartTimer()
Start timer.
static uint64_t microtimer()
Returns the time in microseconds.
static bool EndIter(size_t &iterations)
Mark end of the iteration.
static PMeasure Deinitialize(size_t iterations)
Deinitialize and register.
#define MANAK_INLINE
Check if user has opt for dynamic linking.
static void Initialize()
Initialize a new Timer instance.
Stores the timing information of any run.
static uint64_t & Min()
Get-set min time.
This class handles all the time related queries of libGDL.
static void replaceAll(std::string &str, const std::string &from, const std::string &to)
Replace all occurrences.
static uint64_t & Max()
Get-set max time.
static bool & StateInit()
Get-set initialization state.
static bool & StateIter()
Get-set iteration state.
static PMeasure GetStats(size_t iterations)
Get statistics of current timer instance.
static bool & StateTimer()
Get-set timer state.
static uint64_t & TotalTime()
Get-set total time.
static uint64_t & Start()
Get-set start time.
static void StopTimer()
Stop timer.
static std::string getTimeStamp(bool removeSpaces=false)
Returns current time-stamp as string.
static void StartIter()
Mark start of the iteration.