forked from fast-pack/JavaFastPFOR
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBenchmark.java
More file actions
281 lines (252 loc) · 9.26 KB
/
Copy pathBenchmark.java
File metadata and controls
281 lines (252 loc) · 9.26 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
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
/**
* This code is released under the
* Apache License Version 2.0 http://www.apache.org/licenses/.
*
* (c) Daniel Lemire, http://lemire.me/en/
*/
package me.lemire.integercompression;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import me.lemire.integercompression.synth.ClusteredDataGenerator;
import com.kamikaze.pfordelta.PForDelta;
public class Benchmark {
public static void main(String args[]) {
test(20, 18, 10);
}
public static void testCodec(IntegerCODEC c, int[][] data, int Max,
int repeat, boolean verbose) {
DecimalFormat df = new DecimalFormat("0.00");
DecimalFormat dfspeed = new DecimalFormat("0");
if (verbose)
System.out.println("# " + c.toString());
if (verbose)
System.out
.println("# bits per int, compress speed (mis), decompression speed (mis) ");
long bef, aft;
String line = "";
int N = data.length;
int totalsize = 0;
int maxlength = 0;
for (int k = 0; k < N; ++k) {
totalsize += data[k].length;
if (data[k].length > maxlength)
maxlength = data[k].length;
}
int[] buffer = new int[maxlength + 1024];
int[] dataout = new int[4 * maxlength + 1024];
/* 4x + 1024 to account for the possibility of some negative compression */
int size = 0;
int comptime = 0;
long decomptime = 0;
IntWrapper inpos = new IntWrapper();
IntWrapper outpos = new IntWrapper();
for (int r = 0; r < repeat; ++r) {
size = 0;
for (int k = 0; k < N; ++k) {
int[] backupdata = Arrays.copyOf(data[k], data[k].length);
//
bef = System.nanoTime() / 1000;
inpos.set(1);
outpos.set(0);
if (!(c instanceof IntegratedIntegerCODEC)) {
Delta.delta(backupdata);
}
c.compress(backupdata, inpos, backupdata.length - inpos.get(),
dataout, outpos);
aft = System.nanoTime() / 1000;
//
comptime += aft - bef;
final int thiscompsize = outpos.get() + 1;
size += thiscompsize;
//
bef = System.nanoTime() / 1000;
inpos.set(0);
outpos.set(1);
buffer[0] = backupdata[0];
c.uncompress(dataout, inpos, thiscompsize - 1, buffer, outpos);
if (!(c instanceof IntegratedIntegerCODEC))
Delta.fastinverseDelta(buffer);
aft = System.nanoTime() / 1000;
//
decomptime += aft - bef;
if (outpos.get() != data[k].length)
throw new RuntimeException("we have a bug (diff length) "
+ c + " expected " + data[k].length + " got "
+ outpos.get());
for (int m = 0; m < outpos.get(); ++m)
if (buffer[m] != data[k][m]) {
throw new RuntimeException(
"we have a bug (actual difference), expected "
+ data[k][m] + " found " + buffer[m]
+ " at " + m);
}
}
}
line += "\t" + df.format(size * 32.0 / totalsize);
line += "\t" + dfspeed.format(totalsize * repeat / (comptime));
line += "\t" + dfspeed.format(totalsize * repeat / (decomptime));
if (verbose)
System.out.println(line);
}
public static void testKamikaze(int[][] data, int Max,
int repeat, boolean verbose) {
DecimalFormat df = new DecimalFormat("0.00");
DecimalFormat dfspeed = new DecimalFormat("0");
if (verbose)
System.out.println("# kamikaze PForDelta");
if (verbose)
System.out
.println("# bits per int, compress speed (mis), decompression speed (mis) ");
long bef, aft;
String line = "";
int N = data.length;
int totalsize = 0;
int maxlength = 0;
for (int k = 0; k < N; ++k) {
totalsize += data[k].length;
if (data[k].length > maxlength)
maxlength = data[k].length;
}
int[] buffer = new int[maxlength + 1024];
/* 4x + 1024 to account for the possibility of some negative compression */
int size = 0;
int comptime = 0;
long decomptime = 0;
for (int r = 0; r < repeat; ++r) {
size = 0;
for (int k = 0; k < N; ++k) {
int outpos = 0;
int[] backupdata = Arrays.copyOf(data[k], data[k].length);
//
bef = System.nanoTime() / 1000;
Delta.delta(backupdata);
ArrayList<int[]> dataout = new ArrayList<int[]>(data[k].length/128);
for(int K = 0; K < data[k].length; K+=128) {
final int[] compressedbuf = PForDelta.compressOneBlockOpt(Arrays.copyOfRange(backupdata, K,K+128), 128);
dataout.add(compressedbuf);
outpos += compressedbuf.length;
}
aft = System.nanoTime() / 1000;
//
comptime += aft - bef;
final int thiscompsize = outpos;
size += thiscompsize;
//
bef = System.nanoTime() / 1000;
//buffer[0] = backupdata[0];
ArrayList<int[]> datauncomp = new ArrayList<int[]>(dataout.size());
int deltaoffset = 0;
for(int[] compbuf : dataout ) {
int[] tmpbuf = new int[128];
PForDelta.decompressOneBlock(tmpbuf, compbuf, 128);
tmpbuf[0] += deltaoffset;
Delta.fastinverseDelta(tmpbuf);
deltaoffset = tmpbuf[127];
datauncomp.add(tmpbuf);
}
aft = System.nanoTime() / 1000;
//
decomptime += aft - bef;
if (datauncomp.size() * 128 != data[k].length)
throw new RuntimeException("we have a bug (diff length) "
+ " expected " + data[k].length + " got "
+ datauncomp.size() * 128);
for (int m = 0; m < data[k].length; ++m)
if (datauncomp.get(m/128)[m%128] != data[k][m]) {
throw new RuntimeException(
"we have a bug (actual difference), expected "
+ data[k][m] + " found " + buffer[m]
+ " at " + m);
}
}
}
line += "\t" + df.format(size * 32.0 / totalsize);
line += "\t" + dfspeed.format(totalsize * repeat / (comptime));
line += "\t" + dfspeed.format(totalsize * repeat / (decomptime));
if (verbose)
System.out.println(line);
}
public static void test(int N, int nbr, int repeat) {
ClusteredDataGenerator cdg = new ClusteredDataGenerator();
for (int sparsity = 1; sparsity < 31 - nbr; sparsity += 1) {
System.out.println("# sparsity " + sparsity);
int[][] data = new int[N][];
int Max = (1 << (nbr + sparsity));
System.out.println("# generating random data...");
for (int k = 0; k < N; ++k) {
data[k] = cdg.generateClustered((1 << nbr), Max);
}
System.out.println("# generating random data... ok.");
testKamikaze( data, Max, repeat, false);
testKamikaze( data, Max, repeat, false);
testKamikaze( data, Max, repeat, true);
System.out.println();
testCodec(new IntegratedComposition(new IntegratedBinaryPacking(),
new IntegratedVariableByte()), data, Max, repeat, false);
testCodec(new IntegratedComposition(new IntegratedBinaryPacking(),
new IntegratedVariableByte()), data, Max, repeat, false);
testCodec(new IntegratedComposition(new IntegratedBinaryPacking(),
new IntegratedVariableByte()), data, Max, repeat, true);
System.out.println();
testCodec(new JustCopy(), data, Max, repeat, false);
testCodec(new JustCopy(), data, Max, repeat, false);
testCodec(new JustCopy(), data, Max, repeat, true);
System.out.println();
testCodec(new VariableByte(), data, Max, repeat, false);
testCodec(new VariableByte(), data, Max, repeat, false);
testCodec(new VariableByte(), data, Max, repeat, true);
System.out.println();
testCodec(new IntegratedVariableByte(), data, Max, repeat, false);
testCodec(new IntegratedVariableByte(), data, Max, repeat, false);
testCodec(new IntegratedVariableByte(), data, Max, repeat, true);
System.out.println();
testCodec(new Composition(new BinaryPacking(), new VariableByte()),
data, Max, repeat, false);
testCodec(new Composition(new BinaryPacking(), new VariableByte()),
data, Max, repeat, false);
testCodec(new Composition(new BinaryPacking(), new VariableByte()),
data, Max, repeat, true);
System.out.println();
testCodec(new Composition(new NewPFD(), new VariableByte()), data,
Max, repeat, false);
testCodec(new Composition(new NewPFD(), new VariableByte()), data,
Max, repeat, false);
testCodec(new Composition(new NewPFD(), new VariableByte()), data,
Max, repeat, true);
System.out.println();
testCodec(new Composition(new NewPFDS9(), new VariableByte()), data,
Max, repeat, false);
testCodec(new Composition(new NewPFDS9(), new VariableByte()), data,
Max, repeat, false);
testCodec(new Composition(new NewPFDS9(), new VariableByte()), data,
Max, repeat, true);
System.out.println();
testCodec(new Composition(new OptPFD(), new VariableByte()), data,
Max, repeat, false);
testCodec(new Composition(new OptPFD(), new VariableByte()), data,
Max, repeat, false);
testCodec(new Composition(new OptPFD(), new VariableByte()), data,
Max, repeat, true);
System.out.println();
testCodec(new Composition(new OptPFDS9(), new VariableByte()), data,
Max, repeat, false);
testCodec(new Composition(new OptPFDS9(), new VariableByte()), data,
Max, repeat, false);
testCodec(new Composition(new OptPFDS9(), new VariableByte()), data,
Max, repeat, true);
System.out.println();
testCodec(new Composition(new FastPFOR(), new VariableByte()),
data, Max, repeat, false);
testCodec(new Composition(new FastPFOR(), new VariableByte()),
data, Max, repeat, false);
testCodec(new Composition(new FastPFOR(), new VariableByte()),
data, Max, repeat, true);
System.out.println();
testCodec(new Simple9(), data, Max, repeat, false);
testCodec(new Simple9(), data, Max, repeat, false);
testCodec(new Simple9(), data, Max, repeat, true);
System.out.println();
}
}
}