Result is in eax with the unit of MHz



;Measuring
invoke GetTickCount
push eax
RDTSC
push eax
invoke Sleep,1000
invoke GetTickCount
push eax
RDTSC
;Calculations
pop ecx
pop ebx
pop edx
sub eax,ebx
sub ecx,edx
xor edx,edx
div ecx
xor edx,edx
mov ecx,1000
div ecx


The attached file is a small utility i made to show the CPU frequency
Posted on 2003-09-30 04:14:27 by optimus
I made a mistake in the program (i've updated the attached file)
REALTIME_PRIORITY_CLASS should be replaced with THREAD_PRIORITY_TIME_CRITICAL.
What is the former used for then?
Posted on 2003-09-30 04:25:57 by optimus
Replacing "Sleep 1000" with


mov ecx,0FFFFFFFH
@@:
loop @b

will make the measuring more accurate, but mouse just stuck.
Better place a sleep at the end of the loop
Posted on 2003-09-30 05:02:35 by optimus

Replacing "Sleep 1000" with


mov ecx,0FFFFFFFH
@@:
loop @b

will make the measuring more accurate, but mouse just stuck.
Better place a sleep at the end of the loop


How can you replace a 1000ms Sleep with a loop?
Posted on 2003-09-30 07:15:21 by Delight
The use of GetTickCount/Sleep is little silly. GetTickCount is accurate to 1/1000 Second. Repleace it with QueryPerformanceCounter() and QueryPerformanceFrequency(). These works with resultion of about 1.7Mhz, eg. 1/1.700.000 Second. Thus 1.700.000 /1.000 = 1.700 times better as GetTickCount(). That means you could reduce the waittime of Sleep(1000) downto Sleep(0,55) to get the same accuracy.
There is no need to use higher Threadpriorities because with getTickCount(), QueryPerfoermanceCounter() and RDTSC you have two global and independend sources. All three are independend of the OS task/thread sheduling, thus incrementing thread/process priority is useloss.

Regards, Hagen
Posted on 2003-09-30 13:39:19 by Hagen
this delay can be a what ever length of delay. Using GetTickCount gets the time interval.




How can you replace a 1000ms Sleep with a loop?
Posted on 2003-09-30 13:43:47 by optimus
using QueryPerformanceCounter() is a little bit werid, coz RDTSC is equal to QueryPerformanceCounter() on 586. I need to measure the actual time between the 2 RDTSC. Using higher priority is useful, coz the results are a little bit different.


The use of GetTickCount/Sleep is little silly. GetTickCount is accurate to 1/1000 Second. Repleace it with QueryPerformanceCounter() and QueryPerformanceFrequency(). These works with resultion of about 1.7Mhz, eg. 1/1.700.000 Second. Thus 1.700.000 /1.000 = 1.700 times better as GetTickCount(). That means you could reduce the waittime of Sleep(1000) downto Sleep(0,55) to get the same accuracy.

Regards, Hagen
Posted on 2003-09-30 13:46:42 by optimus
Sorry, it does not work at my computer. PII Win95 OSR2. :(
Posted on 2003-09-30 14:51:51 by JohnFound
hasn't this been discussed quite a number of times already?
Posted on 2003-09-30 16:31:53 by f0dder
I'm a new comer. What's the result of the discussion?
Posted on 2003-10-01 10:04:16 by optimus
who can dis-assemble GetTickCount and Sleep
I'm interested in this.
Posted on 2003-10-01 10:05:44 by optimus
I _assume_ - this is pure speculation - that GetTickCount just returns some internal variable that is updated sometime during the hardware interrupt timer windows has set up. And that Sleep sets some scheduling parameters, either in the TIB or some out-of-reach internal structure... I don't think disassembly of either would be very useful.
Posted on 2003-10-01 12:29:44 by f0dder

I don't think disassembly of either would be very useful.

Nor very legal... or am I wrong?
Posted on 2003-10-01 13:34:17 by scientica
It would be perfectly legal in most of the EU, actually - though using disassembled code directly would probably be illegal. Furthermore, the messed up US of A has other views on this, so just about all disassembly of commercial products are out of topic here.
Posted on 2003-10-01 13:43:12 by f0dder