-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimerTest.dpr
More file actions
46 lines (41 loc) · 1.01 KB
/
TimerTest.dpr
File metadata and controls
46 lines (41 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
program TimerTest;
{$APPTYPE CONSOLE}
{$WARN SYMBOL_PLATFORM OFF}
{$R *.res}
uses
Winapi.Windows,
System.SysUtils;
const
C100NsecPerSec = Round(1E+4);
CPeriod = 80;
var
Freq, Start, Stop: Int64;
FreqMSec: Double;
i: Integer;
Timer: THandle;
Period: Int64;
EndTime: Double;
begin
Win32Check(QueryPerformanceFrequency(Freq));
FreqMSec := Freq / 1E+3;
Timer := CreateWaitableTimer(nil, False, nil);
Win32Check(Timer <> 0);
try
Period := - CPeriod * C100NsecPerSec;
for i := 0 to 9 do begin
Win32Check(QueryPerformanceCounter(Start));
Win32Check(SetWaitableTimer(Timer, Period, 0, nil, nil, False));
if WaitForSingleObject(Timer, INFINITE) = WAIT_OBJECT_0 then begin
EndTime := Start + CPeriod * FreqMSec;
repeat
Win32Check(QueryPerformanceCounter(Stop));
until Stop >= EndTime;
Writeln((Stop - Start) / FreqMSec : 3 : 3);
end else
Writeln('Other result');
end;
finally
CloseHandle(Timer);
end;
Readln;
end.