How do I get the frequency of the CPU?
Posted on 2002-01-21 09:59:21 by dxantos
There !

It is a slow method, though... if someone knows a faster one, I'm interested...
Posted on 2002-01-21 10:25:29 by JCP
queryperformancecounter in api.
more accurate than using sleep.
Some older cpu's dont do it. but i THINK anything mmx on does.

Hope im correct there !
Posted on 2002-01-21 14:05:37 by trancera
Check out my answer in this link. It shows that the OS does the work for you already. I don't explain how to get the values for the 9x flavours of Windows, but they do also have this stored in the registry, but in a different place.
Posted on 2002-01-21 15:05:30 by sluggy
Got it.

One more question, just out of curiosity. On 2 completely different machines (1 pentium3 900mhz, 1 athlon 1,000mhz) I found that Queryperformancefrequency gives the value

3579545

What does this value means? Is it the same on every machine?

sluggy The link is:
http://www.asmcommunity.net/board/index.php?topic=2303&highlight=frequency
Posted on 2002-01-21 16:51:57 by dxantos
3579545

What does this value means? Is it the same on every machine?

The variable that you pass to that function has a pointer returned in it, which you use to access the actual value you want. Check the doco for that function here. And don't forget to check the value returned in eax to see if the function succeeded.
Posted on 2002-01-21 20:35:35 by sluggy

Got it.

One more question, just out of curiosity. On 2 completely different machines (1 pentium3 900mhz, 1 athlon 1,000mhz) I found that Queryperformancefrequency gives the value

3579545

What does this value means? Is it the same on every machine?



That is the reference frequency of the timer chip Windows uses. I forget the exact name of the chip but they are commonly found on PCs.

The values returned from a QueryPerformanceFrequency vary from OSs. Win9x and NT return different values. This one is the same as mine on Win2k. The reference freq. on Win9x is three times slower. Some have stated that some OSs return the CPU freq. but I've never seen it (maybe it's on a Alpha station running Windows, I dunno).

The mathmatical relationship between frequency and time is inversely proportional, ie as frequency increases time decrease or t=1/f. In this situation one clock cycle occurs every 279.365 nsecs. So if a QueryPerformanceCounter check yields a difference of 10 then your timed routine took 2.79 ?sec (microseconds).
Posted on 2002-01-22 06:20:14 by Shadow