News:

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

Timing algorithms

Started by realcr, April 03, 2005, 12:20:13 PM

Previous topic - Next topic

realcr

How do you check the time it takes to algorithms to execute?
Is there any special way to do that?


realcr.

thomasantony

use RDTSC instruction or GetTickCount function b4 and after code and subtract the two values.

Thomas
There are 10 types of people in the world. Those who understand binary and those who don't.


Programmer's Directory. Submit for free

realcr


dsouza123

In the Laboratory there is a thread called   Code timing macros
The macros work well.

Just have/add
    .586

    include \masm32\macros\macros.asm
    include timers.asm
in the include section.  And put the timers.asm in the same folder as your code.

To get cycles
--before the code to test
counter_begin 10, REALTIME_PRIORITY_CLASS
   your code here
counter_end
--after the code

the number of cycles are returned in  eax

OR

To get time in ms
timer_begin 10, REALTIME_PRIORITY_CLASS
   your code
timer_end

Time in ms is returned in eax

The 10 parameter is the number of times to test the code

HIGH_PRIORITY_CLASS can be used instead of REALTIME_PRIORITY_CLASS
(recommended)

If you are writing a GUI program,  example code for console is provided with the macros
    invoke wsprintf, ADDR szBuf, ADDR szFmt, eax
    invoke MessageBox, NULL,ADDR szBuf, ADDR szCap, MB_OK

with the following in the .data
    szFmt db  "cycles  : %10lu  ",0
or
    szFmt db  "ms      : %10lu  ",0

    szBuf  db 32 dup (0)
    szCap  db  "Timing   cycles or ms",0


dsouza123


    .586
    .model flat, stdcall
    option casemap :none

    include \masm32\include\windows.inc
    include \masm32\include\user32.inc
    include \masm32\include\kernel32.inc

    includelib \masm32\lib\user32.lib
    includelib \masm32\lib\kernel32.lib

    include \masm32\macros\macros.asm

    include timers.asm


    .data
       szFmtC db  "cycles  : %10lu  ",0
       szFmtM db  "ms      : %10lu  ",0
       szBuf  db  32 dup (0)
       szCap  db  "Timing   cycles or ms",0   

    .code
start:

    counter_begin 10, HIGH_PRIORITY_CLASS    ; REALTIME_PRIORITY_CLASS
    mov ecx, 2000000
    .while (ecx > 0)
       dec ecx
    .endw
    counter_end

    invoke wsprintf, ADDR szBuf, ADDR szFmtC, eax
    invoke MessageBox, NULL,ADDR szBuf, ADDR szCap, MB_OK

    timer_begin 10, HIGH_PRIORITY_CLASS    ; REALTIME_PRIORITY_CLASS
    mov ecx, 2000000
    .while (ecx > 0)
       dec ecx
    .endw
    timer_end

    invoke wsprintf, ADDR szBuf, ADDR szFmtM, eax
    invoke MessageBox, NULL,ADDR szBuf, ADDR szCap, MB_OK
   
    mov eax, 1
    invoke ExitProcess,eax
end start