Here is some Macros for benchmarking code.

From: -\\\\o//-annabee (faq_at_.@.@szmyggenpv.com)
Date: 02/22/05


Date: Tue, 22 Feb 2005 08:41:06 +0100

To test the following code, Download RosAsm at this adress :
http://betov.free.fr/RosAsm.html

Use the wizards to create an exe file and paste everything below,
*replacing* the main label
____________________________________________________________________________________________

[PrepareForBenchMark | rdtsc | push eax edx | mov ecx #1 | P1: | Push ecx]

[EvaluateForBenchMark| pop ecx | dec ecx | jnz P1< |
  rdtsc | pop ecx ebx | sub eax ebx
  sbb edx ecx | mov ebx #1 | div ebx ]

[RunBenchMark|
  PrepareForBenchMark #1
  push #3>L
    call #2
  EvaluateForBenchMark #1]

;;
EXAMPLE OF USAGE :
Say you have created a routine that take no parameters.
You want to know how many cycles it takes on avarage.
Lets call it "RoutineToBeTested", and write a small one :
;;

[SizeOf_Particle 8]
[PSeudoParticles : ? #(1000*SizeOf_Particle)]
RoutineToBeTested:
mov eax PSeudoParticles
mov ebx eax | add ebx (1000*SizeOf_Particle*4)
L0:
cmp eax ebx | jae L0> ;4 bytes
    inc D§eax ;2 bytes
    add eax SizeOf_Particle ;6 bytes
jmp L0< ; (17 bytes) ;2 bytes

L0: ;14 bytes.
ret

;Try this :

Main:
    RunBenchMark 10000 RoutineToBeTested
    ;at this point, eax will contain the avarage cycle count.
    ;and all pseudoparticles should have an xpostion of 0_2710 which is
10000 in decimal
    int 3 ; this will pause the debugger so you can watch the content of
the eax register.

;;
The above statement will call RoutineToBeTested 10000 times, and average
the report from RDTSC.
Use a higher number for even more accuracy, but it seems from my test
10000 is suffcient. 1000 is sometimes to little, and if you use some small
number like 10, windows will make sure the timings are wrong.

The RunBenchMark macro is able to pass parameters to the Routine to be
tested as well, if you use the Proc / Argument and EndP custom macros
(from one of the startup bases)
;;



Relevant Pages