Mega Code Archive

 
Categories / Delphi / API
 

Using the win api high resolution performance counter

Question: How can I make use of the high resolution performance counter available under Win32? Answer: The following example demonstrates using the TLargeInteger type to query the performance counter. Note that the TLargeInteger type (64 bit integer) can be converted and referenced as a whole by casting it to a Comp type. Example: procedure TForm1.Button1Click(Sender: TObject); var li : TLARGEINTEGER; begin QueryPerformanceFrequency(li); ShowMessage(FloatToStr(Comp(li))); QueryPerformanceCounter(li); ShowMessage(FloatToStr(Comp(li))); QueryPerformanceCounter(li); ShowMessage(FloatToStr(Comp(li))); end;