1 | unit Delays;
|
---|
2 |
|
---|
3 | {$MODE Delphi}
|
---|
4 |
|
---|
5 | interface
|
---|
6 |
|
---|
7 | procedure WaitS(x:integer);
|
---|
8 | procedure WaitMS(x:integer);
|
---|
9 | procedure WaitUS(x:integer);
|
---|
10 | procedure WaitNS(x:integer);
|
---|
11 |
|
---|
12 | procedure Tic(var t:Int64);
|
---|
13 | function TocMS(t:Int64):Int64;
|
---|
14 | function TocUS(t:Int64):Int64;
|
---|
15 | function TocNS(t:Int64):Int64;
|
---|
16 |
|
---|
17 | implementation
|
---|
18 |
|
---|
19 | uses
|
---|
20 | {$IFDEF Windows}Windows,{$ENDIF}LCLIntf, SysUtils, DateUtils, Classes;
|
---|
21 |
|
---|
22 | var
|
---|
23 | persec:Int64;
|
---|
24 |
|
---|
25 | procedure WaitS(x:integer);
|
---|
26 | begin
|
---|
27 | Sleep(x * 1000);
|
---|
28 | end;
|
---|
29 |
|
---|
30 | procedure WaitMS(x:integer);
|
---|
31 | begin
|
---|
32 | Sleep(x);
|
---|
33 | end;
|
---|
34 |
|
---|
35 | procedure WaitUS(x:integer);
|
---|
36 | var
|
---|
37 | f1,f2,c:Int64;
|
---|
38 | begin
|
---|
39 | {$IFDEF Windows}
|
---|
40 | f1:=0; f2:=0;
|
---|
41 | QueryPerformanceCounter(f1);
|
---|
42 | c:=f1+(persec*x) div 1000000;
|
---|
43 | if c = f1 then
|
---|
44 | c:=f1 + 1;
|
---|
45 | repeat
|
---|
46 | QueryPerformanceCounter(f2);
|
---|
47 | until f2>=c;
|
---|
48 | {$ELSE}
|
---|
49 | Sleep(X div 1000);
|
---|
50 | {$ENDIF}
|
---|
51 | end;
|
---|
52 |
|
---|
53 | procedure WaitNS(x:integer);
|
---|
54 | var
|
---|
55 | f1,f2,c:Int64;
|
---|
56 | begin
|
---|
57 | {$IFDEF Windows}
|
---|
58 | f1:=0; f2:=0;
|
---|
59 | QueryPerformanceCounter(f1);
|
---|
60 | c:=f1+(persec*x) div 1000000000;
|
---|
61 | if c = f1 then
|
---|
62 | c:=f1 + 1;
|
---|
63 | repeat
|
---|
64 | QueryPerformanceCounter(f2);
|
---|
65 | until f2>=c;
|
---|
66 | {$ELSE}
|
---|
67 | Sleep(X div 1000);
|
---|
68 | {$ENDIF}
|
---|
69 | end;
|
---|
70 |
|
---|
71 | procedure Tic(var t:Int64);
|
---|
72 | begin
|
---|
73 | {$IFDEF Windows}
|
---|
74 | QueryPerformanceCounter(t);
|
---|
75 | {$ELSE}
|
---|
76 | T := Trunc(Now / OneMillisecond);
|
---|
77 | {$ENDIF}
|
---|
78 | end;
|
---|
79 |
|
---|
80 | function TocMS(t:Int64):Int64; {returns time difference in ms}
|
---|
81 | var
|
---|
82 | t2:Int64;
|
---|
83 | begin
|
---|
84 | {$IFDEF Windows}
|
---|
85 | t2:=0;
|
---|
86 | QueryPerformanceCounter(t2);
|
---|
87 | Result:=((t2 - t) * 1000) div persec;
|
---|
88 | {$ELSE}
|
---|
89 | T := Trunc(Now / OneMillisecond);
|
---|
90 | {$ENDIF}
|
---|
91 | end;
|
---|
92 |
|
---|
93 | function TocUS(t:Int64):Int64; {returns time difference in us}
|
---|
94 | var
|
---|
95 | t2:Int64;
|
---|
96 | begin
|
---|
97 | {$IFDEF Windows}
|
---|
98 | t2:=0;
|
---|
99 | QueryPerformanceCounter(t2);
|
---|
100 | Result:=((t2 - t) * 1000000) div persec;
|
---|
101 | {$ELSE}
|
---|
102 | T := Trunc(Now / OneMillisecond) * 1000;
|
---|
103 | {$ENDIF}
|
---|
104 | end;
|
---|
105 |
|
---|
106 | function TocNS(t:Int64):Int64; {returns time difference in ns}
|
---|
107 | var
|
---|
108 | t2:Int64;
|
---|
109 | begin
|
---|
110 | {$IFDEF Windows}
|
---|
111 | t2:=0;
|
---|
112 | QueryPerformanceCounter(t2);
|
---|
113 | Result:=((t2 - t) * 1000000000) div persec;
|
---|
114 | {$ELSE}
|
---|
115 | T := Trunc(Now / OneMillisecond) * 1000000;
|
---|
116 | {$ENDIF}
|
---|
117 | end;
|
---|
118 |
|
---|
119 | initialization
|
---|
120 | persec:=0;
|
---|
121 | {$IFDEF Windows}
|
---|
122 | QueryPerformanceFrequency(persec);
|
---|
123 | {$ENDIF}
|
---|
124 |
|
---|
125 | end.
|
---|