Tuesday, April 10, 2007

Usage of RDTSC
rdtsc is a VC call and implemented in
assembly. It gets the current ticks of CPU.
1) header files
#include
#pragma intrinsic(__rdtsc)
#include
2) body
LARGE_INTEGER m_largeint;
QueryPerformanceFrequency(&m_largeint); //get the clock frequency of CPU in HZ
unsigned __int64 i = __rdtsc(); // get the current CPU ticks
int c = my_write_packet_to_queuepSendQueue,tLibnet); // the code you want to measure
unsigned __int64 j = __rdtsc(); //
get the current CPU ticks
int m = (j - i)/m_largeint.QuadPart; // the running time in seconds