Time your code  

Send By: Q3 Team
Web : http://www.q3.nu
Email: dlib@q3.nu
Date: 16/03/01

Tip accessed 492 times

 


Here you have an example. The result is shown in Label1:


 procedure TForm1.Button5Click(Sender: TObject);
 var
    Start:longint;
    i,n:integer;
 begin
    Start:=GetTickCount;

    {Your code to measure here}
    n:=0;
    for i:=1 to 9900000 do
    begin
      Inc(n);
    end;

    Label1.Caption:='Elapsed Time in miliseconds:'
                    +IntToStr(GetTickCount-Start);
 end;



If your code is much quicker that 1 milisecond, you can execute it n times inside a loop and then to divide the result for n...


Sent by: Jorge Gilabert (jgilabert@hotmail.com)
To time the code accurately with a precision of processor's cycles of clock, they can be used the hardware counters of high precision of the main board. With my Pentium III 700 I have a precision of 0.8 microsegundos


 var
   freq, start, stop: TLargeInteger;
   lapsoStr: string;

 begin
   QueryPerformanceFrequency(freq);
   QueryPerformanceCounter(Start);

   { aquí va el código a medir el tiempo de ejecución }

   QueryPerformanceCounter(Stop);
   lapsoStr := FloatToStr(round((Stop-Start)/freq));       //en segundos
   lapsoStr := FloatToStr(round((Stop-Start)/freq*1000));  //en milisegundos
 end;




Updated at 16/03/2001 (Hard measure)