1 pass the registry
CString procspeedread () {cstring smhz; char buffer [_max_path]; dword buffs = _max_path; dword dwmhz = _max_path; hkey hkey;
// open the key where the proc speed is hidden: long lError = RegOpenKeyEx (HKEY_LOCAL_MACHINE, "HARDWARE // DESCRIPTION // System // CentralProcessor // 0", 0, KEY_READ, & hKey); if (! LError = ERROR_SUCCESS) { // if the key is not found, tell the user why: formatmessage (format_message_from_system, null, lerror, 0, buffer, _max_path, 0); AFXMESSAGEBOX (BUFFER); Return "N / A";}
// Query The Key: RegQueryValueex (HKEY, "~ MHz", NULL, NULL, (LPBYTE) & dwmhz, & bufsize
// Convert the dword to a cstring: smhz.format ("% i", dwmhz);
Return SMHz;}
2 Calculate the clock cycle and high precision counter (non-Intergenever, such as AMD, please change RDTSC Macro)
float CGettheProcessorSpeedDlg :: ProcSpeedCalc () {/ * RdTSC:. It's the Pentium instruction "ReaD Time Stamp Counter" It measures thenumber of clock cycles that have passed since the processor was reset, as a64-bit number That's what the _emit lines do. . * / # define rdtsc __asm _emit 0x0f __asm _emit 0x31