-
Notifications
You must be signed in to change notification settings - Fork 5
/
Unit_Fast_Test.pas
204 lines (146 loc) · 4.03 KB
/
Unit_Fast_Test.pas
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
unit Unit_Fast_Test;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
type
TFormTest = class(TForm)
Memo1: TMemo;
Button1: TButton;
LTest: TLabel;
Button2: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
procedure TestDay(const D:TDateTime);
procedure TestDayOfYear(const D:TDateTime);
procedure TestMonth(const D:TDateTime);
procedure TestYear(const D:TDateTime);
public
{ Public declarations }
end;
var
FormTest: TFormTest;
implementation
{$R *.dfm}
uses
System.Diagnostics, Tee.FastDateTime, DateUtils;
function Diff(const ASlow,AFast:Int64):String;
var tmp : Single;
begin
tmp:=100-(AFast*100/ASlow);
result:='('+FormatFloat('0.##%',tmp)+' faster)';
end;
const
TestTimes=5000000;
procedure TFormTest.TestYear(const D:TDateTime);
var t1 : TStopwatch;
t2,t3 : Int64;
t : Integer;
y : Word;
begin
t1:=TStopwatch.StartNew;
for t:=1 to TestTimes do
y:=YearOf(D);
t2:=t1.ElapsedMilliseconds;
Memo1.Lines.Add('YearOf: '+t2.ToString+' msec '+y.ToString);
t1:=TStopwatch.StartNew;
for t:=1 to TestTimes do
y:=TFastDateTime.YearOf(D);
t3:=t1.ElapsedMilliseconds;
Memo1.Lines.Add('Fast YearOf: '+t3.ToString+' msec '+y.ToString+' '+Diff(t2,t3));
end;
procedure TFormTest.TestMonth(const D:TDateTime);
var t1 : TStopwatch;
t2, t3 : Int64;
t : Integer;
day : Word;
begin
t1:=TStopwatch.StartNew;
for t:=1 to TestTimes do
day:=MonthOf(D);
t2:=t1.ElapsedMilliseconds;
Memo1.Lines.Add('MonthOf: '+t2.ToString+' msec '+day.ToString);
t1:=TStopwatch.StartNew;
for t:=1 to TestTimes do
day:=TFastDateTime.MonthOf(D);
t3:=t1.ElapsedMilliseconds;
Memo1.Lines.Add('Fast MonthOf: '+t3.ToString+' msec '+day.ToString+' '+Diff(t2,t3));
end;
procedure TFormTest.TestDay(const D:TDateTime);
var t1 : TStopwatch;
t2,t3 : Int64;
t : Integer;
day : Word;
begin
t1:=TStopwatch.StartNew;
for t:=1 to TestTimes do
day:=DayOf(D);
t2:=t1.ElapsedMilliseconds;
Memo1.Lines.Add('DayOf: '+t2.ToString+' msec '+day.ToString);
t1:=TStopwatch.StartNew;
for t:=1 to TestTimes do
day:=TFastDateTime.DayOf(D);
t3:=t1.ElapsedMilliseconds;
Memo1.Lines.Add('Fast DayOf: '+t3.ToString+' msec '+day.ToString+' '+Diff(t2,t3));
end;
procedure TFormTest.TestDayOfYear(const D:TDateTime);
var t1 : TStopwatch;
t2,t3 : Int64;
t : Integer;
day : Word;
begin
t1:=TStopwatch.StartNew;
for t:=1 to TestTimes do
day:=DayOfTheYear(D);
t2:=t1.ElapsedMilliseconds;
Memo1.Lines.Add('DayOfYear: '+t2.ToString+' msec '+day.ToString);
t1:=TStopwatch.StartNew;
for t:=1 to TestTimes do
day:=TFastDateTime.DayOfTheYear(D);
t3:=t1.ElapsedMilliseconds;
Memo1.Lines.Add('Fast DayOfYear: '+t3.ToString+' msec '+day.ToString+' '+Diff(t2,t3));
end;
procedure TFormTest.Button1Click(Sender: TObject);
var t : Integer;
y,m,d : Word;
begin
LTest.Caption:='';
for t:=1 to Round(EncodeDate(2100,12,31)) do
begin
DecodeDate(t,y,m,d);
if y<>TFastDateTime.YearOf(t) then
raise Exception.Create('Wrong year: '+DateTimeToStr(t))
else
if m<>TFastDateTime.MonthOf(t) then
raise Exception.Create('Wrong month: '+DateTimeToStr(t))
else
if d<>TFastDateTime.DayOf(t) then
raise Exception.Create('Wrong day: '+DateTimeToStr(t))
else
if DayOfTheYear(t)<>TFastDateTime.DayOfTheYear(t) then
raise Exception.Create('Wrong day of year: '+DateTimeToStr(t))
end;
LTest.Caption:='Ok';
end;
procedure TFormTest.Button2Click(Sender: TObject);
var D : TDateTime;
begin
Memo1.Clear;
D:=Now;
//D:=EncodeDate(1994,7,1);
TestYear(D);
Memo1.Lines.Add('');
TestMonth(D);
Memo1.Lines.Add('');
TestDay(D);
Memo1.Lines.Add('');
TestDayOfYear(D);
end;
procedure TFormTest.FormCreate(Sender: TObject);
begin
Button2Click(Self);
end;
end.