26#pragma intrinsic(__rdtsc)
31 #include <sys/types.h>
32 #include <sys/sysctl.h>
33 #include <mach/mach_time.h>
37#include <mach/mach_time.h>
70 Timer(
bool startImmediately =
false);
88 void reset(
bool startAfterReset =
false);
97 UInt64 getNumTicks()
const;
103 bool isRunning()
const;
106 static UInt64 getCurrentTick();
135 if (startImmediately)
157 m_total += (now - m_start);
200 agxAssert1(s_clockSpeed >= 0,
"Timer class not properly initialized, forgot to call agx::init() ?");
210 const UInt64 retVal = __rdtsc();
212#elif defined(AGX_APPLE_IOS) || defined(__APPLE__)
213 return mach_absolute_time();
214#elif (defined(__GNUC__) || defined(__ICC)) && (defined(__i386__) || defined(__x86_64__)) && !defined(HAVE_TICK_COUNTER)
229 unsigned long long int lowbits, highbits;
230 __asm__ __volatile__(
"rdtsc":
"=a" (lowbits),
"=d"(highbits) : : );
232 unsigned long int lowbits, highbits;
233 __asm__ __volatile__(
"pushal\n\t" "cpuid\n\t" "popal\n\t" "rdtsc":
"=a" (lowbits),
"=d"(highbits) );
237 return (((
unsigned long long int)highbits<<32) | (
unsigned long long int)lowbits);
240 agxAbort1(
"Timer::getCurrentTick failed!");
253 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()