30 #pragma intrinsic(__rdtsc)
36 #include <sys/types.h>
37 #include <sys/sysctl.h>
41 #if AGX_USE_CPP11_TIMERS()
46 #include <mach/mach_time.h>
82 Timer(
bool startImmediately =
false);
100 void reset(
bool startAfterReset =
false);
109 UInt64 getNumTicks()
const;
115 bool isRunning()
const;
118 static UInt64 getCurrentTick();
129 static void initClockSpeed();
133 #if defined(_MSC_VER)
134 static UInt64 getCurrentTickWindows();
140 #if AGX_USE_CPP11_TIMERS()
141 std::high_resolution_clock::time_point m_start;
142 std::duration<agx::Real64> m_total;
158 if (startImmediately)
170 #if AGX_USE_CPP11_TIMERS()
171 m_start = std::high_resolution_clock::now();
183 #if AGX_USE_CPP11_TIMERS()
184 std::high_resolution_clock::time_point now = std::high_resolution_clock::now();
185 std::duration<Real64> duration = duration_cast<std::duration<Real64>>(now - m_start);
189 m_total += (now - m_start);
226 #if AGX_USE_CPP11_TIMERS()
229 std::high_resolution_clock::time_point now = std::high_resolution_clock::now();
230 std::duration<Real64> duration = duration_cast<std::duration<Real64>>(now - m_start);
231 std::duration<Real64> total = m_total + duration;
232 return total.count() *
Real64(1000);
236 return m_total.count() *
Real64(1000);;
248 agxAssert1(s_clockSpeed >= 0,
"Timer class not properly initialized, forgot to call agx::init() ?");
257 #if defined(_MSC_VER)
259 const UInt64 retVal = getCurrentTickWindows();
261 const UInt64 retVal = __rdtsc();
264 #elif defined(AGX_APPLE_IOS)
265 return mach_absolute_time();
266 #elif defined (__GNUC__) && ! defined(__INTEL_COMPILER) && defined(__ia64__)
267 unsigned long long int val;
268 __asm__ __volatile__(
"mov %0=ar.itc" :
"=r"(val) ::
"memory");
270 #elif defined(__INTEL_COMPILER) && defined(__ia64__) && !defined(HAVE_TICK_COUNTER)
271 return __getReg(_IA64_REG_AR_ITC);
272 #elif defined(__ECC) && defined(__ia64__) && !defined(HAVE_TICK_COUNTER)
273 return __getReg(_IA64_REG_AR_ITC);
274 #elif (defined(__GNUC__) || defined(__ICC)) && (defined(__i386__) || defined(__x86_64__)) && !defined(HAVE_TICK_COUNTER)
289 unsigned long long int lowbits, highbits;
290 __asm__ __volatile__(
"rdtsc":
"=a" (lowbits),
"=d"(highbits) : : );
292 unsigned long int lowbits, highbits;
293 __asm__ __volatile__(
"pushal\n\t" "cpuid\n\t" "popal\n\t" "rdtsc":
"=a" (lowbits),
"=d"(highbits) );
297 return (((
unsigned long long int)highbits<<32) | (
unsigned long long int)lowbits);
300 agxAbort1(
"Timer::getCurrentTick failed!");
313 return clockSpeed() * (
Real64)ticks;
UInt64 getStartTick() const
Timer(bool startImmediately=false)
Creates a timer.
void stop()
Stops the timer.
UInt64 getNumTicks() const
Report execution time in CPU cycles.
UInt64 AGXCORE_EXPORT getStartTick()
The Timer class permits timing execution speed with the same refinement as the built in hardware cloc...
static UInt64 getCurrentTick()
Real64 getTime() const
Report total elapsed time since start in milliseconds, excluding intervals when the timer was suspend...
void start()
Starts the timer.
static Real64 convertToMs(UInt64 ticks)
#define agxAssert1(expr, msg)
void reset(bool startAfterReset=false)
Clear all data.