Skip to content

Instantly share code, notes, and snippets.

@ugovaretto
Created January 30, 2014 09:38
Show Gist options
  • Save ugovaretto/8705363 to your computer and use it in GitHub Desktop.
Save ugovaretto/8705363 to your computer and use it in GitHub Desktop.
Get CPU clock cycles
//FROM STACKOVERFLOW: http://stackoverflow.com/questions/275004/c-timer-function-to-provide-time-in-nano-seconds
inline __int64 GetCpuClocks()
{
// Counter
struct { int32 low, high; } counter;
// Use RDTSC instruction to get clocks count
__asm push EAX
__asm push EDX
__asm __emit 0fh __asm __emit 031h // RDTSC
__asm mov counter.low, EAX
__asm mov counter.high, EDX
__asm pop EDX
__asm pop EAX
// Return result
return *(__int64 *)(&counter);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment