From 41f3a33352ea3a0f5ddcdf7ff78e4244873718cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Wawrzyk?= Date: Thu, 2 Aug 2018 16:09:38 +0200 Subject: [PATCH] Refactor and adjust config --- .../virtuslab/zipops/bench/BenchUtil.scala | 31 +++++++++++++++++++ .../zipops/bench/DeleteBenchmarks.scala | 25 ++------------- .../zipops/bench/MergeBenchmarks.scala | 26 ++-------------- 3 files changed, 37 insertions(+), 45 deletions(-) diff --git a/src/main/scala/org/virtuslab/zipops/bench/BenchUtil.scala b/src/main/scala/org/virtuslab/zipops/bench/BenchUtil.scala index 4b97f5d..96af669 100644 --- a/src/main/scala/org/virtuslab/zipops/bench/BenchUtil.scala +++ b/src/main/scala/org/virtuslab/zipops/bench/BenchUtil.scala @@ -2,6 +2,37 @@ package org.virtuslab.zipops.bench import java.io.File import java.nio.file.{ Files, StandardCopyOption } +import java.util.concurrent.TimeUnit.SECONDS + +import org.openjdk.jmh.annotations._ +import org.virtuslab.zipops.{ Zip4jZipOps, ZipFsZipOps, ZipOps } + +trait ZipOpsBench { + + def run(ops: ZipOps): Unit + + @Benchmark + @Fork(value = 1) + @Warmup(iterations = 10, time = 10, timeUnit = SECONDS) + @Measurement(iterations = 15, time = 15, timeUnit = SECONDS) + @BenchmarkMode(Array(Mode.Throughput)) + @OutputTimeUnit(SECONDS) + def zip4j(): Unit = { + run(Zip4jZipOps) + } + + @Benchmark + @Fork(value = 1) + @Warmup(iterations = 10, time = 10, timeUnit = SECONDS) + @Measurement(iterations = 15, time = 15, timeUnit = SECONDS) + @BenchmarkMode(Array(Mode.Throughput)) + @OutputTimeUnit(SECONDS) + def zipfs(): Unit = { + run(ZipFsZipOps) + } + + +} trait BenchUtil { diff --git a/src/main/scala/org/virtuslab/zipops/bench/DeleteBenchmarks.scala b/src/main/scala/org/virtuslab/zipops/bench/DeleteBenchmarks.scala index db08705..c85c3a4 100644 --- a/src/main/scala/org/virtuslab/zipops/bench/DeleteBenchmarks.scala +++ b/src/main/scala/org/virtuslab/zipops/bench/DeleteBenchmarks.scala @@ -1,10 +1,9 @@ package org.virtuslab.zipops.bench import java.io.File -import java.util.concurrent.TimeUnit.SECONDS import org.openjdk.jmh.annotations._ -import org.virtuslab.zipops.{ Zip4jZipOps, ZipFsZipOps } +import org.virtuslab.zipops.ZipOps class BigJarDeleteBench extends DeleteBenchmark("scala-library-2.12.6.jar") { @@ -45,7 +44,7 @@ class SmallJarDeleteBench extends DeleteBenchmark("scala-xml_2.12-1.0.6.jar") { } @State(Scope.Thread) -abstract class DeleteBenchmark(jar: String) extends BenchUtil { +abstract class DeleteBenchmark(jar: String) extends ZipOpsBench with BenchUtil { var jarFile: File = _ @@ -61,23 +60,5 @@ abstract class DeleteBenchmark(jar: String) extends BenchUtil { jarFile.delete() } - @Benchmark - @Fork(value = 1) - @Warmup(iterations = 3, time = 10, timeUnit = SECONDS) - @Measurement(iterations = 5, time = 10, timeUnit = SECONDS) - @BenchmarkMode(Array(Mode.Throughput)) - @OutputTimeUnit(SECONDS) - def zip4jRemove(): Unit = { - Zip4jZipOps.removeEntries(jarFile, toDelete) - } - - @Benchmark - @Fork(value = 1) - @Warmup(iterations = 3, time = 10, timeUnit = SECONDS) - @Measurement(iterations = 5, time = 10, timeUnit = SECONDS) - @BenchmarkMode(Array(Mode.Throughput)) - @OutputTimeUnit(SECONDS) - def zipfsRemove(): Unit = { - ZipFsZipOps.removeEntries(jarFile, toDelete) - } + override def run(ops: ZipOps): Unit = ops.removeEntries(jarFile, toDelete) } diff --git a/src/main/scala/org/virtuslab/zipops/bench/MergeBenchmarks.scala b/src/main/scala/org/virtuslab/zipops/bench/MergeBenchmarks.scala index 6fb7f7d..cdb9307 100644 --- a/src/main/scala/org/virtuslab/zipops/bench/MergeBenchmarks.scala +++ b/src/main/scala/org/virtuslab/zipops/bench/MergeBenchmarks.scala @@ -2,9 +2,7 @@ package org.virtuslab.zipops.bench import java.io.File -import org.virtuslab.zipops.{ Zip4jZipOps, ZipFsZipOps } -import java.util.concurrent.TimeUnit.SECONDS - +import org.virtuslab.zipops.ZipOps import org.openjdk.jmh.annotations._ class MergeBenchSmall extends MergeBench("scala-xml_2.12-1.0.6.jar", "zip-ops_2.12-0.1.jar") @@ -12,7 +10,7 @@ class MergeBenchSmall extends MergeBench("scala-xml_2.12-1.0.6.jar", "zip-ops_2. class MergeBenchBig extends MergeBench("scala-library-2.12.6.jar", "scala-xml_2.12-1.0.6.jar") @State(Scope.Thread) -abstract class MergeBench(target: String, source: String) extends BenchUtil { +abstract class MergeBench(target: String, source: String) extends ZipOpsBench with BenchUtil { var targetFile: File = _ var sourceFile: File = _ @@ -28,23 +26,5 @@ abstract class MergeBench(target: String, source: String) extends BenchUtil { targetFile.delete() } - @Benchmark - @Fork(value = 1) - @Warmup(iterations = 3, time = 10, timeUnit = SECONDS) - @Measurement(iterations = 5, time = 10, timeUnit = SECONDS) - @BenchmarkMode(Array(Mode.Throughput)) - @OutputTimeUnit(SECONDS) - def zip4jMerge(): Unit = { - Zip4jZipOps.mergeArchives(targetFile, sourceFile) - } - - @Benchmark - @Fork(value = 1) - @Warmup(iterations = 3, time = 10, timeUnit = SECONDS) - @Measurement(iterations = 5, time = 10, timeUnit = SECONDS) - @BenchmarkMode(Array(Mode.Throughput)) - @OutputTimeUnit(SECONDS) - def zipfsMerge(): Unit = { - ZipFsZipOps.mergeArchives(targetFile, sourceFile) - } + override def run(ops: ZipOps): Unit = ops.mergeArchives(targetFile, sourceFile) }