Longlong getfrequency (DWORD sleeptime)//Get CPU Frequency{DWORD Low1=0, HIGH1 =0, Low2 =0, HIGH2 =0; Large_integer Fq, St, Ed; /*the QueryPerformanceFrequency () function should be called before timing to obtain the clock frequency of the internal timer of the machine. Then QueryPerformanceCounter () is called before and after the event that requires strict timing, and the exact time elapsed can be calculated using the difference in technology and the frequency of the clock two times. */:: QueryPerformanceFrequency (&FQ);//Precise timing (returns the frequency of hardware-supported high-precision counters):: QueryPerformanceCounter (&ST);//Get start time__asm {//the number of times to obtain the current CPURDTSC mov low1, eax mov high1, edx}:: Sleep (Sleeptime); //suspend a thread for a moment:: QueryPerformanceCounter (&ed);//Get end Time__asm {RDTSC//Read the CPU timestamp countermov low2, eax mov high2, edx}//Convert CPU time period to 64-bit integerLonglong begin= (Longlong) high1 << +|Low1; Longlong End= (Longlong) high2 << +|Low2; //divide the number of CPU cycles obtained two times by the interval time, that is, the frequency of the CPU//because the sleep function of Windows has an error of approximately 15 milliseconds, the precise timing of windows will prevail return(End-begin) *fq. QuadPart/(ed. QuadPart-St. QuadPart);}
Transferred from: http://blog.csdn.net/kofandlizi/article/details/6253801
C + + Get CPU frequency (RPM)