20 #include <agx/config/AGX_USE_CPP11_TIMERS.h>
30 #pragma intrinsic(__rdtsc)
36 #include <sys/types.h>
37 #include <sys/sysctl.h>
38 #include <mach/mach_time.h>
42 #if AGX_USE_CPP11_TIMERS()
47 #include <mach/mach_time.h>
83 Timer(
bool startImmediately =
false);
101 void reset(
bool startAfterReset =
false);
110 UInt64 getNumTicks()
const;
116 bool isRunning()
const;
119 static UInt64 getCurrentTick();
134 #if defined(_MSC_VER)
136 static UInt64 getCurrentTickWindows();
141 #if AGX_USE_CPP11_TIMERS()
142 std::high_resolution_clock::time_point m_start;
143 std::duration<agx::Real64> m_total;
159 if (startImmediately)
171 #if AGX_USE_CPP11_TIMERS()
172 m_start = std::high_resolution_clock::now();
184 #if AGX_USE_CPP11_TIMERS()
185 std::high_resolution_clock::time_point now = std::high_resolution_clock::now();
186 std::duration<Real64> duration = duration_cast<std::duration<Real64>>(now - m_start);
190 m_total += (now - m_start);
227 #if AGX_USE_CPP11_TIMERS()
230 std::high_resolution_clock::time_point now = std::high_resolution_clock::now();
231 std::duration<Real64> duration = duration_cast<std::duration<Real64>>(now - m_start);
232 std::duration<Real64> total = m_total + duration;
233 return total.count() *
Real64(1000);
237 return m_total.count() *
Real64(1000);;
249 agxAssert1(s_clockSpeed >= 0,
"Timer class not properly initialized, forgot to call agx::init() ?");
258 #if defined(_MSC_VER)
260 const UInt64 retVal = getCurrentTickWindows();
262 const UInt64 retVal = __rdtsc();
265 #elif defined(AGX_APPLE_IOS) || defined(__APPLE__)
266 return mach_absolute_time();
267 #elif defined (__GNUC__) && ! defined(__INTEL_COMPILER) && defined(__ia64__)
268 unsigned long long int val;
269 __asm__ __volatile__(
"mov %0=ar.itc" :
"=r"(val) ::
"memory");
271 #elif defined(__INTEL_COMPILER) && defined(__ia64__) && !defined(HAVE_TICK_COUNTER)
272 return __getReg(_IA64_REG_AR_ITC);
273 #elif defined(__ECC) && defined(__ia64__) && !defined(HAVE_TICK_COUNTER)
274 return __getReg(_IA64_REG_AR_ITC);
275 #elif (defined(__GNUC__) || defined(__ICC)) && (defined(__i386__) || defined(__x86_64__)) && !defined(HAVE_TICK_COUNTER)
290 unsigned long long int lowbits, highbits;
291 __asm__ __volatile__(
"rdtsc":
"=a" (lowbits),
"=d"(highbits) : : );
293 unsigned long int lowbits, highbits;
294 __asm__ __volatile__(
"pushal\n\t" "cpuid\n\t" "popal\n\t" "rdtsc":
"=a" (lowbits),
"=d"(highbits) );
298 return (((
unsigned long long int)highbits<<32) | (
unsigned long long int)lowbits);
301 agxAbort1(
"Timer::getCurrentTick failed!");
314 return clockSpeed() * (
Real64)ticks;
The Timer class permits timing execution speed with the same refinement as the built in hardware cloc...
static UInt64 getCurrentTick()
static Real64 convertToMs(UInt64 ticks)
void stop()
Stops the timer.
void start()
Starts the timer.
Real64 getTime() const
Report total elapsed time since start in milliseconds, excluding intervals when the timer was suspend...
UInt64 getNumTicks() const
Report execution time in CPU cycles.
static void initClockSpeed()
For internal use only.
UInt64 getStartTick() const
void reset(bool startAfterReset=false)
Clear all data.
Timer(bool startImmediately=false)
Creates a timer.
#define agxAssert1(expr, msg)
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
UInt64 AGXCORE_EXPORT getStartTick()