typedef struct _BinInt32
{
__int32 i32[2];
} BigInt32;
typedef struct _BigInt64
{
__int64 i64;
} BigInt64;
typedef union _bigInt
{ BigInt32 int32val;
BigInt64 int64val;
} BigInt;
下面的代码从操作系统获得时钟计数器的高位和低位,分别填写__int64数据的两个32 bit部分:
BigInt start_ticks, end_ticks;
_asm {
RDTSC
mov start_ticks.int32val.i32[0], eax
mov start_ticks.int32val.i32[4], edx
}
RDTSC(ReaD Time Stamp Counter)是一个汇编指令,它的功能是把时间戳计数器的内容装入EAX和EDX寄存器。执行上述代码后,start_ticks就包含了完整的时钟计数。再次调用上面的代码,把start_ticks替换成end_ticks,再从end_ticks减去start_ticks,就得到了两次调用期间流逝的时钟周期。