How To Count Procedure Performance
23rd July 2008
Hello all delphi.com readers, Lately I got a lot of job, and the deadline was very-very tight.So I Can not post too regularly so for you all delphi.com readers I apologize, you guys have to wait, life must go on right ? ![]()
Ok, now I want to share a trick on how we to measure the performance of one procedure or one syntax.
Let say that we have one syntax that we want to measure, let say it was the TStringList and then we want to know if this TStringList performance on sorting the text so let’s try..
don’t forget to uses this unit.
uses
Windows,SysUtils;
procedure Testing;
var a: TStrings;
CountStart,CountStop:Int64;
Begin
a:= TStringList.Create;
try
a.Add('Test 1');
a.Add('Coba1');
a.Add('Lari1');
a.Sorted:= True;
QueryPerformanceCounter(CountStart);
a.Sort;
QueryPerformanceCounter(CounterStop);
ShowMessage('Sorting Done in '+FloatToStr(((CounterStop-CounterStart)/CounterStart)*1000+'Miliseconds'));
Finally
a.Free;
End;
end;
So When the sorting is done..a pop up message will show to tell us how much milisecond was used to do the sorting. that way we can calculate which procedure from our source code that took big amount of process time and we can directly trimmed it down.Oh yes the QueryPerformanceCounter was an Windows Api function, and it was returning in nanoseconds so we need to multiply by 1000000 if we want in seconds also according to MSDN it uses Hardware timer so if your hardware not supporting it will return value 0.
So by this now we cant see which procedure or which syntax was taking so long to operate and we can find the best algorithm method to choose so over all our program will significantly increasing on the speed. Ok That’s all today happy testing and measuring..

July 26th, 2008 at 4:36 am
Good work.
Since 1994 I have been using Object Pascal for development (mainly about Computer Graphics), and I’m glad to see a site like yours.
Keep spreading good tech information.
Best regards,
————————-
Leonardo C. de Almeida
http://picturetopeople.blogspot.com
July 28th, 2008 at 10:38 am
Nice tutorial. Thank you
July 31st, 2008 at 11:01 pm
Having and keep your job is more important than blogging, right? So it doesn’t matter!
Good luck with the job!
About the tutorials.. To be honest..I don’t understand it! ;p
August 1st, 2008 at 5:34 am
@bioteck
Certainly bro, job is more important as I’ve already got warning for passing my deadline ,
)
August 3rd, 2008 at 2:34 am
just reading your post here
keep it up.