Skip to content

Commit 64f9cda

Browse files
committed
make each input file 8mb
1 parent 2cf3c79 commit 64f9cda

File tree

2 files changed

+52
-34
lines changed

2 files changed

+52
-34
lines changed

benchmarks/src/main/java/org/elasticsearch/benchmark/common/compress/FSSTCompressBenchmark.java

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -47,26 +47,30 @@ public static class CompressionMetrics {
4747
public double compressionRatio;
4848
}
4949

50+
private static final int MB_8 = 8 * 1024 * 1024;
51+
private byte[] concatenateTo8mb(byte[] contentBytes) {
52+
byte[] bytes = new byte[MB_8 + 8];
53+
int i = 0;
54+
while (i < MB_8) {
55+
int remaining = MB_8 - i;
56+
int len = Math.min(contentBytes.length, remaining);
57+
System.arraycopy(contentBytes, 0, bytes, i, len);
58+
i += len;
59+
}
60+
return bytes;
61+
}
62+
5063
@Setup(Level.Trial)
5164
public void setup() throws IOException {
5265
String content = Files.readString(Path.of(dataset), StandardCharsets.UTF_8);
53-
byte[] bytes = FSST.toBytes(content);
54-
byte[] bytes2 = new byte[bytes.length + 8];
55-
System.arraycopy(bytes, 0, bytes2, 0, bytes.length);
56-
input = bytes2;
57-
offsets = new int[] { 0, bytes.length };
5866

59-
outBuf = new byte[bytes.length];
67+
byte[] contentBytes = FSST.toBytes(content);
68+
input = concatenateTo8mb(contentBytes);
69+
offsets = new int[]{0, MB_8};
70+
outBuf = new byte[MB_8];
6071
outOffsets = new int[2];
6172
}
6273

63-
@Benchmark
64-
public void makeSample(Blackhole bh, CompressionMetrics metrics) {
65-
List<byte[]> sample = FSST.makeSample(input, offsets);
66-
var symbolTable = FSST.SymbolTable.buildSymbolTable(sample);
67-
bh.consume(sample);
68-
}
69-
7074
@Benchmark
7175
public void compressFSST(Blackhole bh, CompressionMetrics metrics) {
7276
List<byte[]> sample = FSST.makeSample(input, offsets);
@@ -96,19 +100,19 @@ public void compressLZ4Fast(Blackhole bh, CompressionMetrics metrics) throws IOE
96100
metrics.compressionRatio = compressedSize / (double) inputSize;
97101
}
98102

99-
@Benchmark
100-
public void compressLZ4High(Blackhole bh, CompressionMetrics metrics) throws IOException {
101-
int inputSize = offsets[1];
102-
103-
var dataInput = new ByteBuffersDataInput(List.of(ByteBuffer.wrap(input)));
104-
var dataOutput = new ByteArrayDataOutput(outBuf);
105-
106-
Compressor compressor = CompressionMode.HIGH_COMPRESSION.newCompressor();
107-
compressor.compress(dataInput, dataOutput);
108-
109-
long compressedSize = dataOutput.getPosition();
110-
bh.consume(dataOutput);
111-
112-
metrics.compressionRatio = compressedSize / (double) inputSize;
113-
}
103+
// @Benchmark
104+
// public void compressLZ4High(Blackhole bh, CompressionMetrics metrics) throws IOException {
105+
// int inputSize = offsets[1];
106+
//
107+
// var dataInput = new ByteBuffersDataInput(List.of(ByteBuffer.wrap(input)));
108+
// var dataOutput = new ByteArrayDataOutput(outBuf);
109+
//
110+
// Compressor compressor = CompressionMode.HIGH_COMPRESSION.newCompressor();
111+
// compressor.compress(dataInput, dataOutput);
112+
//
113+
// long compressedSize = dataOutput.getPosition();
114+
// bh.consume(dataOutput);
115+
//
116+
// metrics.compressionRatio = compressedSize / (double) inputSize;
117+
// }
114118
}

benchmarks/src/main/java/org/elasticsearch/benchmark/common/compress/FSSTDecompressBenchmark.java

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.nio.charset.StandardCharsets;
2626
import java.nio.file.Files;
2727
import java.nio.file.Path;
28+
import java.util.Arrays;
2829
import java.util.List;
2930
import java.util.concurrent.TimeUnit;
3031

@@ -36,7 +37,8 @@
3637
@State(Scope.Benchmark)
3738
public class FSSTDecompressBenchmark {
3839

39-
@Param({ "fsst", "lz4_high", "lz4_fast" })
40+
// @Param({ "fsst", "lz4_high", "lz4_fast" })
41+
@Param({"fsst", "lz4_fast"})
4042
public String compressionType;
4143

4244
@Param("")
@@ -58,14 +60,26 @@ public class FSSTDecompressBenchmark {
5860
// fsst specific
5961
private FSST.SymbolTable symbolTable;
6062

63+
private static final int MB_8 = 8 * 1024 * 1024;
64+
private byte[] concatenateTo8mb(byte[] contentBytes) {
65+
byte[] bytes = new byte[MB_8 + 8];
66+
int i = 0;
67+
while (i < MB_8) {
68+
int remaining = MB_8 - i;
69+
int len = Math.min(contentBytes.length, remaining);
70+
System.arraycopy(contentBytes, 0, bytes, i, len);
71+
i += len;
72+
}
73+
return bytes;
74+
}
75+
6176
@Setup(Level.Trial)
6277
public void setup() throws IOException {
6378
String content = Files.readString(Path.of(dataset), StandardCharsets.UTF_8);
64-
byte[] bytes = FSST.toBytes(content);
65-
originalSize = bytes.length;
66-
input = new byte[originalSize + 8];
67-
offsets = new int[] { 0, bytes.length };
68-
System.arraycopy(bytes, 0, input, 0, bytes.length);
79+
byte[] contentBytes = FSST.toBytes(content);
80+
originalSize = MB_8;
81+
input = concatenateTo8mb(contentBytes);
82+
offsets = new int[]{0, originalSize};
6983

7084
outBuf = new byte[input.length];
7185
outOffsets = new int[2];

0 commit comments

Comments
 (0)