News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Bench Mark - Clock ?

Started by MDWLibby, March 01, 2014, 03:20:13 AM

Previous topic - Next topic

MDWLibby

Just learning this stuff again.  Can anyone tell me what I might use to test code snippets.  It looks to be a bit task ;) to do manually.

dedndave

most of us use Michael Webster's code timing macros
they can be downloaded here

http://masm32.com/board/index.php?topic=49.0

unzip the contents and place it in \Masm32\Macros
then, you can time code, something like this....

;###############################################################################################

        .XCREF
        .NoList
        INCLUDE    \Masm32\Include\Masm32rt.inc
        .686p
        .MMX
        .XMM
        INCLUDE    \Masm32\Macros\Timers.asm
        .List

;###############################################################################################

Loop_Count = 50000000  ;try to select a value that makes passes about 0.5 seconds

;###############################################################################################

        .DATA

;***********************************************************************************************

        .DATA?

;###############################################################################################

        .CODE

;***********************************************************************************************

_main   PROC

        INVOKE  GetCurrentProcess
        INVOKE  SetProcessAffinityMask,eax,1
        INVOKE  Sleep,750

        mov     ecx,5

Loop00: push    ecx

        counter_begin Loop_Count,HIGH_PRIORITY_CLASS

;code to be timed
xor edx,edx
mov eax,100
mov ecx,10
div ecx

        counter_end

        print   str$(eax),32
        pop     ecx
        dec     ecx
        jnz     Loop00

        print   chr$(13,10)
        inkey
        INVOKE  ExitProcess,0

_main   ENDP

;###############################################################################################

        END     _main

MDWLibby

Thanks Dave; I'll give it a try.

hutch--

There are a few Windows API functions that can be used for timings if you understand the limitations of them running in normal user mode (ring 3). Anything that runs in ring 3 suffers priority interference from the operating system and this reduces the accuracy of the timings.

Usually a benchmark is run for long enough to average out the interference where a very short duration benchmark fluctuates wildly in its timing.

Look at GetTickCount() for simple timings that run for a half a second or longer and there are a few others.

MDWLibby

Thanks; I was thinking I may have read about that.  It seems only 10% of what I read doesn't fall out.

jj2007

One more option, effective resolution 0.3 microseconds:

include \masm32\MasmBasic\MasmBasic.inc      ; download
      Init
      PrintCpu
      NanoTimer()      ; initialise
      mov ecx, 1000000
@@:      nop
      loopnz @B
      Print Str$("\n%i\tµs for loopz", NanoTimer(µs))      ; µs, ms or s

      NanoTimer()
      mov ecx, 1000000
@@:      nop
      dec ecx
      jnz @B
      Print Str$("\n%i\tµs for dec ecx", NanoTimer(µs))

      Exit
end start

Output:
Intel(R) Celeron(R) M CPU        420  @ 1.60GHz (MMX, SSE, SSE2, SSE3)

4377    µs for loopz
977     µs for dec ecx

MDWLibby

Thanks JJ
I'm just getting started so I'm asking questions that might be rather obvious to most of you.  I was looking at some example code, and noticed the label @@: and after a compair I seen @B I just thought it was a type-O.  I'm sure now it probably is not.  Could you give me a little help to where I might find it documented?  I'm sure its one of those things that found its way out, in all the reading I'm doing.

hutch--

Look for the term anonymous labels in MASM.

@@: is an un-named label.

jmp @B is jump to last previous @@:
jmp @F is jump to next @@: label.

MDWLibby

Thanks Hutch; I found it in Local Code Labels.