9ea Subj : Re: CPU Speed! To : borland.public.cpp.borlandcpp From : "Ed Mulroy [TeamB]" Date : Mon Oct 27 2003 12:41 pm If you want the CPU speed in MHz then try this. Assuming that you saved it as Speed.c then a command line to build it might be one of those below: If it is to be run on a machine which has BC++ on it bcc32 -RT- -x- -WM- -WR speed.c noeh32.lib speed.exe is about 6K, dynamic linked If it is to be run on a machine which does not have BC++ on it bcc32 -RT- -x- -WM- -W speed.c noeh32.lib speed.exe is about 26K, static linked Borland C++ does not have BASM, the built-in assembler. To handle inline assembly it will shell out to TASM32.EXE or whatever assembler you have configured it to use. ------------------------------- #define STRICT #include #pragma inline #define RDTSC __emit__(0x0F, 0x31) /* rdtsc instruction */ static DWORD GetCpuSpeed(void) { LARGE_INTEGER liFreq; LARGE_INTEGER li1; LARGE_INTEGER li2; DWORD timestamp[2]; HANDLE hThread; int nPriority; hThread = GetCurrentThread(); nPriority = GetThreadPriority(hThread); QueryPerformanceFrequency(&liFreq); liFreq.QuadPart /= 10; SetThreadPriority(hThread, THREAD_PRIORITY_HIGHEST); RDTSC; __asm mov dword ptr [timestamp],eax __asm mov dword ptr [timestamp + 4],edx QueryPerformanceCounter(&li1); do { QueryPerformanceCounter(&li2); } while((li2.QuadPart - li1.QuadPart) < liFreq.QuadPart); RDTSC; __asm { sub eax,dword ptr [timestamp] sbb edx,dword ptr [timestamp+4] mov ebx,100000 div ebx push eax } SetThreadPriority(hThread, nPriority); __asm pop eax return _EAX; } #pragma argsused int WINAPI WinMain(HINSTANCE h, HINSTANCE hp, LPSTR s, int n) { char buff[32]; wsprintf(buff, " %u MHz ", GetCpuSpeed()); MessageBox(HWND_DESKTOP, buff, " CPU Speed ", MB_OK); return 0; } ------------------------------- .. Ed > Majid wrote in message > news:3f9d2dd4$2@newsgroups.borland.com... > > I want to calculate speed of my CPU and I have these properties > of my Processor : > > >>Raw Frequency > >>Normal Frequency > >>In cycles > >>ExTicks > > I just want to get my CPU speed in Mhz and I don't know how to > combine these information. Can somebody help me? . 0