Sign in Join
Wiki copytemporary

QueryPerformanceCounter: what changed

Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.

Title: QueryPerformanceCounter

OldNewLine
1+Maybe the one microsecond timestamp is too long for your program. You can access the Windows API Performance Counter using code such as shown below. Note that this API may not be as reliable as you might hope. For more information see <http://www.virtualdub.org/blog/pivot/entry.php?id=106>
2+
3+``` pascal
4+unit Unit1;
5+{$mode objfpc}{$H+}
6+interface
7+
8+uses
9+ Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
10+ StdCtrls, Windows;
11+
12+type
13+ { TForm1 }
14+ TForm1 = class(TForm)
15+ procedure FormClick(Sender: TObject);
16+ private
17+ { private declarations }
18+ public
19+ { public declarations }
20+ end;
21+ var
22+ Form1: TForm1;
23+implementation
24+
25+{ TForm1 }
26+
27+procedure TForm1.FormClick(Sender: TObject);
28+var
29+ PerformanceCounter: int64;
30+ PerformanceFrequency: int64;
31+begin
32+ if QueryPerformanceFrequency(PerformanceFrequency)
33+ and QueryPerformanceCounter(PerformanceCounter)
34+ then ShowMessage('Freq:' + IntToStr(PerformanceFrequency)
35+ + ', Counter:' + IntToStr(PerformanceCounter))
36+ else ShowMessage('Sorry, performance counters not supported.');
37+end;
38+
39+initialization
40+
41+{$I unit1.lrs}
42+
43+end.
44+```
45+
46+---
47+*From the Free Pascal wiki, page "QueryPerformanceCounter", as it stood on 2020-02-23 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history