All Delphi

Everything You Want To Know From VCL, Tips To Snippet All Everything About Delphi And CodeGear Related

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 ? :D
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..

Bookmark and Share
Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay
  • LinkedIn
  • Live
  • StumbleUpon
  • Technorati

5 Responses to “How To Count Procedure Performance”

  1. Leonardo Says:

    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

  2. Drunken Dragon Says:

    Nice tutorial. Thank you

  3. BioTecK Says:

    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

  4. admin Says:

    @bioteck

    Certainly bro, job is more important as I’ve already got warning for passing my deadline , :) )

  5. Tess Says:

    just reading your post here :) keep it up.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>