The MASM Forum

General => The Campus => Topic started by: MDWLibby on March 01, 2014, 03:20:13 AM

Title: Bench Mark - Clock ?
Post by: MDWLibby on March 01, 2014, 03:20:13 AM
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.
Title: Re: Bench Mark - Clock ?
Post by: dedndave on March 01, 2014, 04:29:22 AM
most of us use Michael Webster's code timing macros
they can be downloaded here

http://masm32.com/board/index.php?topic=49.0 (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
Title: Re: Bench Mark - Clock ?
Post by: MDWLibby on March 01, 2014, 04:46:05 AM
Thanks Dave; I'll give it a try.
Title: Re: Bench Mark - Clock ?
Post by: hutch-- on March 01, 2014, 08:24:22 AM
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.
Title: Re: Bench Mark - Clock ?
Post by: MDWLibby on March 01, 2014, 08:59:06 AM
Thanks; I was thinking I may have read about that.  It seems only 10% of what I read doesn't fall out.
Title: Re: Bench Mark - Clock ?
Post by: jj2007 on March 01, 2014, 09:08:02 AM
One more option, effective resolution 0.3 microseconds:

include \masm32\MasmBasic\MasmBasic.inc      ; download (http://masm32.com/board/index.php?topic=94.0)
      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
Title: Re: Bench Mark - Clock ?
Post by: MDWLibby on March 02, 2014, 08:41:28 AM
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.
Title: Re: Bench Mark - Clock ?
Post by: hutch-- on March 02, 2014, 09:01:36 AM
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.
Title: Re: Bench Mark - Clock ?
Post by: MDWLibby on March 02, 2014, 01:13:48 PM
Thanks Hutch; I found it in Local Code Labels.