DelphiFAQ Home Search:

Measure execution time in your program

 

comments3 comments. Current rating: 4 stars (2 votes). Leave comments and/ or rate it.

Simply call

  • StartClock before and
  • StopClock after
the part of the program you want to clock, as shown in the example:

var { must be global }
  hr, mins, se, s1 : word;

procedure StartClock;
begin
  GetTime (hr,mins,se,s1);
end;

procedure StopClock;
var
  siz : longint;
  hr2, min2, se2  : word;
begin
  GetTime (hr2, min2, se2, s1);
  siz := se2-se+(min2-mins)*60+(hr2-hr)*60*60;
  ShowMessage (IntToStr(siz) + ' seconds');
end;

{ sample how to use it.. very simple }
begin
  StartClock;
  for i := 1 to 100 do
    MyProcedure(i);
  StopClock;
end.

Comments:

2008-01-06, 15:18:47
anonymous from Poland  
rating
It doesn't work :( I tried it in Delphi 2007 and errors occure :(
2008-04-08, 15:15:31
Alexandar from Macedonia  
rating
It works for Pascal 0.7

I just changed this line

ShowMessage (IntToStr(siz) + ' seconds');

is changed into

writeln(siz,' seconds');
2008-05-28, 14:38:55
anonymous from Finland  
Works easily. Might need to make few changes to the code depending of the delphi/pascal version but that should not be any problem to any experienced coder.

 

 

NEW: Optional: Register   Login
Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option, or post under a registered account.
 

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity.
The owner of this web site reserves the right to delete such material.

photo Add a picture: