The MASM Forum Archive 2004 to 2012

General Forums => The Laboratory => Topic started by: Manos on January 22, 2005, 05:44:08 PM

Title: GetTickCount
Post by: Manos on January 22, 2005, 05:44:08 PM
Much frequently,I use GetTickCount API to test my code.
For example:

LOCAL var :DWORD
invoke GetTickCount
mov var,eax

someLoop........

invoke GetTickCount
sub eax,var
PrintDec eax

I execute the above code about 10 times and I take the average value.
This code works OK in Win9x,and WinMe,
but now that I have WinXP this code does not works properly.
I take values with long variations.

What about this ?

Regards,
Manos.

Title: Re: GetTickCount
Post by: Mark_Larson on January 22, 2005, 06:44:41 PM
GetTickCount doesn't always generate enough accuracy.  You need to use RDTSC and to set the process priority to real time.  Look at MichaelW's post about macros that do timing.
Title: Re: GetTickCount
Post by: lifewire on January 22, 2005, 06:52:25 PM
or use QueryPerformance-Counter/Frequency
Title: Re: GetTickCount
Post by: Mark_Larson on January 23, 2005, 01:45:58 AM
Quote from: lifewire on January 22, 2005, 06:52:25 PM
or use QueryPerformance-Counter/Frequency

QueryPerformanceCounter actually does a RDTSC itself, but it has extra overhead because you are calling a procedure.  So doing RDTSC manually causes less overhead in your timing code.  Here is an example of setting the priority class. It is VERY important for getting consistent timings.


invoke GetCurrentProcess
invoke SetPriorityClass,eax,REALTIME_PRIORITY_CLASS
Title: Re: GetTickCount
Post by: hutch-- on January 23, 2005, 02:27:06 AM
Manos,

I have not had problems with GetTickCount() but I did with Win2k until I set the process priority.

            invoke SetPriorityClass,FUNC(GetCurrentProcess),REALTIME_PRIORITY_CLASS

            invoke GetTickCount
            push eax

            ; ---------------------
            ; run your code here
            ; ---------------------

            invoke GetTickCount
            pop ecx
            sub eax, ecx

            fn MessageBox,hWnd,str$(eax),str$(rcnt),MB_OK

            invoke SetPriorityClass,FUNC(GetCurrentProcess),NORMAL_PRIORITY_CLASS

Title: Re: GetTickCount
Post by: Manos on January 23, 2005, 07:00:57 AM
Yes,you are right.
With Win2K and later,the solution is the pair:

SetPriorityClass,FUNC(GetCurrentProcess),REALTIME_PRIORITY_CLASS

SetPriorityClass,FUNC(GetCurrentProcess),NORMAL_PRIORITY_CLASS

Thanks All,
Manos.