-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTEST.PAS
45 lines (35 loc) · 957 Bytes
/
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
unit test;
interface
uses
xcrt, utils;
type
TTestProc = function (obj: pointer): boolean;
TTestWrite = procedure(s: string);
procedure setTestWriteProc(p: TTestWrite);
procedure measure(name: string; proc: TTestProc; obj: pointer; times: word);
implementation
var
testWrite: TTestWrite;
procedure setTestWriteProc(p: TTestWrite);
begin
testWrite := p;
end;
procedure defaultWrite(s: string); far;
begin
writeln(s);
end;
procedure measure(name: string; proc: TTestProc; obj: pointer; times: word);
var
i: word;
ticks: longint;
begin
testWrite('start measure ' + name + ' (' + inttostr(times) + ' times)');
i := times;
ticks := C_TICKS^;
while (i>0) and proc(obj) do dec(i);
ticks := (C_TICKS^ - ticks) div times;
testWrite('ended measure ' + name + ': ' +longtostr(trunc(ticks * C_TICK_DURATION)) + 'ms');
end;
begin
setTestWriteProc(defaultWrite);
end.