Created
January 30, 2014 09:38
-
-
Save ugovaretto/8705363 to your computer and use it in GitHub Desktop.
Get CPU clock cycles
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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