News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

GetTickCount

Started by Manos, January 22, 2005, 05:44:08 PM

Previous topic - Next topic

Manos

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.


Mark_Larson

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.
BIOS programmers do it fastest, hehe.  ;)

My Optimization webpage
htttp://www.website.masmforum.com/mark/index.htm

lifewire

or use QueryPerformance-Counter/Frequency

Mark_Larson

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
BIOS programmers do it fastest, hehe.  ;)

My Optimization webpage
htttp://www.website.masmforum.com/mark/index.htm

hutch--

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

Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Manos

#5
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.