@@ -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}
0 commit comments