-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestUnit.pas
161 lines (155 loc) · 3.63 KB
/
TestUnit.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
unit TestUnit;
interface
uses
System.SysUtils,
classes,
zstd,
xxhash,
zlib,
System.Diagnostics ;
procedure DoTest; cdecl;
implementation
var data,c,d,cc,dd : TMemoryStream;
ZC : TZstdCompressStream;
ZD : TZSTDDecompressStream;
ZLC : TZCompressionStream;
ZLD : TZDeCompressionStream;
W: TStopWatch;
procedure WriteInfo(Op : String; St : TStream);
begin
st.Position := 0;
write(Op,' in ',W.ElapsedMilliseconds,'ms ');
writeln('Size: ',St.Size,' XXHash3: ',THASHXXH3.HashAsString(St));
W.Reset;
st.Position := 0;
end;
procedure DoTest; cdecl;
begin
writeln('zstd version: ',ZSTD_VERSION_STRING);
writeln;
try
{ TODO -oUser -cConsole Main : Insert code here }
W := TStopWatch.Create;
data := TMemoryStream.Create;
data.LoadFromFile('glibc-2.31.tar');
data.Position := 0;
writeln('Orginal Size: ',data.SIZE,' Orginal XXHash3: ',THASHXXH3.HashAsString(data));
writeln;
C := TMemoryStream.Create;
D := TMemoryStream.Create;
cc := TMemoryStream.Create;
dd := TMemoryStream.Create;
data.Position := 0;
cc.SetSize(0);
W.Start;
cc.position:= 0;
ZLC := TZCompressionStream.Create(clFastest,cc);
ZLC.CopyFrom(data,data.Size);
ZLC.Free;
W.Stop;
WriteInfo('Zlib Fastest Compress',cc);
W.Start;
dd.position := 0;
ZLD := TZDecompressionStream.Create(CC);
dd.CopyFrom(ZLD);
ZLD.Free;
W.Stop;
WriteInfo('Zlib Fastest DeCompress',dd);
writeln;
data.Position := 0;
c.SetSize(0);
W.Start;
c.position := 0;
ZC := TZSTDCompressStream.Create(C,1);
ZC.CopyFrom(data,data.Size);
ZC.Free;
W.Stop;
WriteInfo('ZSTD Fastest Compress',c);
W.Start;
d.position := 0;
ZD := TZSTDDecompressStream.Create(C,false);
D.CopyFrom(ZD);
ZD.Free;
WriteInfo('ZSTD Fastest DeCompress',d);
writeln;
cc.SetSize(0);
data.Position := 0;
W.Start;
cc.position:= 0;
ZLC := TZCompressionStream.Create(clDefault,cc);
ZLC.CopyFrom(data,data.Size);
ZLC.Free;
W.Stop;
WriteInfo('Zlib Default Compress',cc);
W.Start;
dd.position := 0;
ZLD := TZDecompressionStream.Create(CC);
DD.CopyFrom(ZLD);
ZLD.Free;
W.Stop;
WriteInfo('Zlib Default DeCompress',dd);
writeln;
data.position := 0;
c.SetSize(0);
W.Start;
c.position := 0;
ZC := TZSTDCompressStream.Create(C);
ZC.CopyFrom(data,data.Size);
ZC.Free;
W.Stop;
WriteInfo('ZSTD Default Compress',c);
W.Start;
d.position := 0;
ZD := TZSTDDecompressStream.Create(C,false);
D.CopyFrom(ZD);
ZD.Free;
W.Stop;
WriteInfo('ZSTD Default DeCompress',d);
writeln;
data.Position := 0;
cc.SetSize(0);
W.Start;
cc.position:= 0;
ZLC := TZCompressionStream.Create(clMAX,cc);
ZLC.CopyFrom(data,data.Size);
ZLC.Free;
W.Stop;
WriteInfo('Zlib MAX Compress',cc);
W.Start;
dd.position := 0;
ZLD := TZDecompressionStream.Create(CC);
DD.CopyFrom(ZLD);
ZLD.Free;
W.Stop;
WriteInfo('Zlib MAX DeCompress',dd);
writeln;
data.position := 0;
c.SetSize(0);
W.Start;
c.position := 0;
ZC := TZSTDCompressStream.Create(C,9);
ZC.CopyFrom(data,data.Size);
ZC.Free;
W.Stop;
WriteInfo('ZSTD LV9 Compress',c);
W.Start;
d.position := 0;
ZD := TZSTDDecompressStream.Create(C,false);
D.CopyFrom(ZD);
ZD.Free;
W.Stop;
WriteInfo('ZSTD LV9 DeCompress',d);
writeln;
data.Free;
c.free;
d.free;
cc.free;
dd.free;
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
writeln('Done! press ENTER to quit');
readln;
end;
end.