Einzelnen Beitrag anzeigen

Fukiszo
(Gast)

n/a Beiträge
 
#26

AW: Windows.GetTickCount64 auch unter Windows XP?

  Alt 15. Jan 2018, 22:18
ich nutz QueryPerformanceCounter immer wenn ich was benche, ich finde es sehr präzise.
Nur als vergleich gegen GetTickCount egal ob x86 oder x64.
Als alternative halt.
Ich hoffe der code ist mit neueren delphi versionen kompatibel.

Delphi-Quellcode:
{QueryPerformanceCounter uses the PC's clock counter just as GetTickCount, but it
reads the current value of the countdown register in the timer chip to gain more
accuracy -- down to 1.193MHz (about 800ns).

However, it takes 5 to 10us to call QueryPerformanceCounter, because it has to
do several port I/O instructions to read this value.

If you are running multiprocessor NT, QueryPerformanceCounter uses the Pentium
cycle counter.

You should not be using the raw value of QueryPerformanceCounter; you should
always divide by QueryPerformanceFrequency to convert to some known time base.
QueryPerformanceCounter doesn't run at the same rate on all machines.

The example below shows how to use it in Delphi 3/4:
}


type
  TInt64 = TLargeInteger;
var
  Frequency, lpPerformanceCount1, lpPerformanceCount2 : TLargeInteger;

begin
  QueryPerformanceCounter(TInt64((@lpPerformanceCount1)^));

  // activity to measure
  my_proc;

  QueryPerformanceCounter(TInt64((@lpPerformanceCount2)^));
  QueryPerformanceFrequency(TInt64((@Frequency)^));

  // this shows the time in ns
  ShowMessage(IntToStr(Round(1000000 * (lpPerformanceCount2.QuadPart -
                       lpPerformanceCount1.QuadPart) / Frequency.QuadPart)));
end;
  Mit Zitat antworten Zitat