Programming CPU

zhaozj2021-02-16  138

The source program is as follows:

// compile: CL / TC

#define win32_Lean_and_mean # include

#include

#define rdst _asm _emit 0x0f _ASM _EMIT 0X31

float GetCpuSpeed ​​() {__int64 cStart = 0, cEnd = 0; unsigned __int64 nCtr = 0, nCtrStop = 0, nFrq = 0; QueryPerformanceFrequency ((LARGE_INTEGER *) & nFrq); QueryPerformanceCounter ((LARGE_INTEGER *) & nCtrStop); nCtrStop = nFrq ; _ASM {RDST MOV DWORD PTR CSTART, EAX MOV DWORD PTR [CStart 4], EDX} DO {QueryperFormanceCounter (Large_integer *) & nctr);} While (NCTR

_asm

{

RDST

Mov DWORD PTR CEND, EAX

MOV DWORD PTR [CEND 4], EDX

}

Return (Float) CStart / 1000000;

}

INT main () {Printf ("CPU Speed:% 5.3F MHz / N", getcpuspeed ()); return 0;}

转载请注明原文地址:https://www.9cbs.com/read-8741.html

New Post(0)