inline unsigned __int64 GetCycleCount()
{
__asm _emit 0x0F
__asm _emit 0x31
}
//以后在需要计数器的场合,可以像使用普通的Win32 API一样,调用两次GetCycleCount函数,比较两个返回值的差,像这样:
//
unsigned long t;
t = (unsigned long)GetCycleCount();
//Do Something time-intensive ...
t -= (unsigned long)GetCycleCount();
UNIX下可以的,我在FreeBSD下试过,当然,只能在Pentium上用,因为使用了嵌入汇编:
inline long long GetCycleCount()
{
__asm ("RDTSC");
}
main()
{
long long count;
count = GetCycleCount();
sleep(1);
printf("%d/n", GetCycleCount() - count);
}