Skip to content

Instantly share code, notes, and snippets.

@maxkleiner
Created January 11, 2021 20:18
Show Gist options
  • Save maxkleiner/32ec49c2ae95157fd13033e09238afab to your computer and use it in GitHub Desktop.
Save maxkleiner/32ec49c2ae95157fd13033e09238afab to your computer and use it in GitHub Desktop.
CPUClockFrequency
const
SHighResCounterError = 'High resolution counter error';
function CPUClockFrequency: Word64;
var
Freq : int64;
begin
Freq := 0;
if not QueryPerformanceFrequency(Freq) then
xraise (ETimerError2.Create(SHighResCounterError));
if Freq = 0 then
xraise (ETimerError2.Create(SHighResCounterError));
Result := Word64(Freq);
end;
procedure InitHighResolutionCounter;
var
Freq : Word64;
begin
Freq := CPUClockFrequency;
HighResolutionFrequency := Freq;
HighResolutionMillisecondFactor := Freq div 1000;
HighResolutionMicrosecondFactor := Freq div 1000000;
if HighResolutionMicrosecondFactor = 0 then
Xraise (ETimerError2.Create(SHighResCounterError));
HighResolutionCounterInit := True;
end;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment