I came across an article on CodeGuru that defines some macros using the Time Stamp Method matsp described. http://www.codeguru.com/cpp/misc/mis...cle.php/c3895/
It requires an intel Pentium to work so is not very portable but it measures the cycles using CPUID to serialize the instructions.
Code:
#ifdef _DEBUG
#define PERF_DECLARE \
__int64 MSRB, MSRE; \
void *mrsb = &MSRB; \
void *mrse = &MSRE; \
char perfmtrbuf[100];
#define PERF_START \
{_asm mov eax, 0 \
_asm cpuid \
_asm rdtsc \
_asm mov ebx, mrsb \
_asm mov dword ptr [ebx], eax \
_asm mov dword ptr [ebx+4], edx \
_asm mov eax, 0 \
_asm cpuid}
#define PERF_STOP \
{_asm mov eax, 0 \
_asm cpuid \
_asm rdtsc \
_asm mov ebx, mrse \
_asm mov dword ptr [ebx], eax \
_asm mov dword ptr [ebx+4], edx \
_asm mov eax, 0 \
_asm cpuid}
#define PERF_REPORT \
{_ui64toa(MSRE-MSRB, perfmtrbuf, 10); \
printf("Cycles needed: %s\n", perfmtrbuf);}
#else
#define PERF_DECLARE
#define PERF_START
#define PERF_STOP
#define PERF_REPORT
#endif