Re: How to time the execution of a method?



"Nurax" <nurax@xxxxxxxxxxxxxx> wrote in message
news:ffn4s8$ltn$1@xxxxxxxxxxxxxxx
[...]
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;

This solves a different problem. You measure a thousand times,
then average all the individual measurements. If the resolution
of GetTickCount is not sufficient to measure the time taken by
calling x, that won't help. The average of a thousand zeroes is
still zero.

If you want to reduce quantisation error or jitter, this is a
good way. If you want to improve resolution, call GetTickCount
exactly twice.

Groetjes,
Maarten Wiltink


.



Relevant Pages

  • Re: Help! Problem on CPU usage and performance tuning.
    ... > GetTickCountfunction just as comparison with GetThreadTimes(). ... This resolution is stored in "nt! ... So you see that the resolution is better than with "GetTickCount" but it ... > test time is a way. ...
    (microsoft.public.win32.programmer.kernel)
  • Re: Accurate time measurement
    ... "Multiple statements execute before either ... GetTickCount or timeGetTime record a change" and adding, ... increase the resolution of both GetTickCount and timeGetTime using ...
    (microsoft.public.vb.general.discussion)
  • Re: Timer accuracy.
    ... >> resolution timer and is more accurate than GetTickCount ... >> Private Declare Function timeGetTime _ ... >You have to be a bit careful about the timeGetTime function Jerry. ...
    (microsoft.public.vb.general.discussion)
  • Re: high resolution elapsed time???
    ... resolution. ... Private Declare Function GetTickCount Lib "kernel32" As Long ... '// from the last time this routine was called. ... Dim THIS_TIME As Long ...
    (microsoft.public.vc.language)
  • RE: C# Thread.Sleep malfunction
    ... In XP Pro I have found Sleep() has a 15ms resolution as the default and ... GetTickCount() has a 1ms resolution by default. ...
    (microsoft.public.dotnet.framework)