Re: How to time the execution of a method?



The problem is that I have three possible algorithms to re-inflate the
screen, and I want to know which is the most efficient on average.
I've tried using the following:

function TimeMethod(x: TMethod): TDateTime;
var s,e: TDateTime;
begin
s:=Now;
x;
e:=Now;
TimeMethod:=86400*(e-s);
end;

Maybe x is too fast to time;
Try this:

function TimeMethod(x: TMethod): string;
var i, t, tot: Cardinal;
begin
tot := 0;
for i := 1 to 1000 do
begin
t := GetTickCount;
x;
Inc(tot, GetTickCount - t);
end;
result := FormatFloat('Seconds: 0.0000', tot/1000);
end;


.



Relevant Pages