changeset 887:8975b49f535f

apache commons compress benchmark
author Devel 1
date Mon, 26 Mar 2018 09:46:08 +0200
parents ea6918227f40
children b9d643afb2fc
files stress-tester-benchmark/pom.xml stress-tester-benchmark/src/main/java/com/passus/compress/CommonsCompress.java stress-tester-benchmark/src/main/java/com/passus/compress/Decompression.java
diffstat 3 files changed, 98 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/stress-tester-benchmark/pom.xml	Fri Mar 23 14:42:49 2018 +0100
+++ b/stress-tester-benchmark/pom.xml	Mon Mar 26 09:46:08 2018 +0200
@@ -157,6 +157,12 @@
             <version>2.9.0</version>
         </dependency>
 
+        <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-compress</artifactId>
+            <version>1.16.1</version>
+        </dependency>
+
     </dependencies>
     
     <build>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/stress-tester-benchmark/src/main/java/com/passus/compress/CommonsCompress.java	Mon Mar 26 09:46:08 2018 +0200
@@ -0,0 +1,91 @@
+package com.passus.compress;
+
+import com.passus.ambience.utils.TestResourceUtils;
+import static com.passus.compress.Decompression.DEFLATE_PATH;
+import com.passus.data.HeapByteBuff;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.concurrent.TimeUnit;
+import org.apache.commons.compress.compressors.brotli.BrotliCompressorInputStream;
+import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream;
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.BenchmarkMode;
+import org.openjdk.jmh.annotations.Fork;
+import org.openjdk.jmh.annotations.Measurement;
+import org.openjdk.jmh.annotations.Mode;
+import org.openjdk.jmh.annotations.OutputTimeUnit;
+import org.openjdk.jmh.annotations.Scope;
+import org.openjdk.jmh.annotations.State;
+import org.openjdk.jmh.annotations.Warmup;
+import org.openjdk.jmh.runner.Runner;
+import org.openjdk.jmh.runner.options.Options;
+import org.openjdk.jmh.runner.options.OptionsBuilder;
+
+/**
+ *
+ * @author mikolaj.podbielski
+ */
+@State(Scope.Thread)
+@BenchmarkMode(Mode.AverageTime)
+@OutputTimeUnit(TimeUnit.MICROSECONDS)
+@Fork(value = 1)
+@Measurement(iterations = 6)
+@Warmup(iterations = 5)
+public class CommonsCompress {
+
+    static final String DEFLATE_PATH = TestResourceUtils.getFile("bin/deflate.bin").getAbsolutePath();
+    static final String GZIP_PATH = TestResourceUtils.getFile("bin/gzip.bin").getAbsolutePath();
+    static final String BROTLI_PATH = TestResourceUtils.getFile("bin/gzip.bin.br").getAbsolutePath();
+    private final byte[] DEFLATE_BYTES;
+    private final byte[] GZIP_BYTES;
+    private final byte[] BROTLI_BYTES;
+
+    private final byte[] intermediateBuffer = new byte[16384];
+
+    private int compBufferSize = 1024;
+
+    public CommonsCompress() {
+        try {
+            DEFLATE_BYTES = Files.readAllBytes(Paths.get(DEFLATE_PATH));
+            GZIP_BYTES = Files.readAllBytes(Paths.get(GZIP_PATH));
+            BROTLI_BYTES = Files.readAllBytes(Paths.get(BROTLI_PATH));
+        } catch (IOException ex) {
+            throw new RuntimeException(ex);
+        }
+    }
+
+    @Benchmark
+    public int apacheGzipDec() throws IOException {
+        ByteArrayInputStream bais = new ByteArrayInputStream(GZIP_BYTES);
+        GzipCompressorInputStream is = new GzipCompressorInputStream(bais);
+        HeapByteBuff out = new HeapByteBuff(GZIP_BYTES.length);
+        int b;
+        while ((b = is.read(intermediateBuffer)) != -1) {
+            out.append(intermediateBuffer, 0, b);
+        }
+        return out.length();
+    }
+    
+    @Benchmark
+    public int apacheBrotliDec() throws IOException {
+        ByteArrayInputStream bais = new ByteArrayInputStream(BROTLI_BYTES);
+        BrotliCompressorInputStream is = new BrotliCompressorInputStream(bais);
+        HeapByteBuff out = new HeapByteBuff(GZIP_BYTES.length);
+        int b;
+        while ((b = is.read(intermediateBuffer)) != -1) {
+            out.append(intermediateBuffer, 0, b);
+        }
+        return out.length(); // 146004
+    }
+
+    public static void main(String[] args) throws Exception {
+        CommonsCompress cc = new CommonsCompress();
+        System.out.println(cc.apacheGzipDec());
+        System.out.println(cc.apacheBrotliDec());
+        
+        Options opt = new OptionsBuilder().include(CommonsCompress.class.getSimpleName() + ".*").build();
+        new Runner(opt).run();
+    }
+}
--- a/stress-tester-benchmark/src/main/java/com/passus/compress/Decompression.java	Fri Mar 23 14:42:49 2018 +0100
+++ b/stress-tester-benchmark/src/main/java/com/passus/compress/Decompression.java	Mon Mar 26 09:46:08 2018 +0200
@@ -33,7 +33,7 @@
  */
 @State(Scope.Thread)
 @BenchmarkMode(Mode.AverageTime)
-@OutputTimeUnit(TimeUnit.MILLISECONDS)
+@OutputTimeUnit(TimeUnit.MICROSECONDS)
 @Fork(value = 1)
 @Measurement(iterations = 6)
 @Warmup(iterations = 5)