diff --git a/tests/jmh/ArrayBench.scala b/tests/jmh/ArrayBench.scala index e891ba5a..81d277ba 100644 --- a/tests/jmh/ArrayBench.scala +++ b/tests/jmh/ArrayBench.scala @@ -1,26 +1,31 @@ package test import java.util.concurrent.TimeUnit.* - import org.openjdk.jmh.annotations.* + @State(Scope.Benchmark) class ArrayState: - val array = (1 to 100).toArray - + val array: Array[Int] = (1 to 100).toArray val h = 123 class ArrayBench: @Benchmark - @BenchmarkMode(Array(Mode.SingleShotTime, Mode.Throughput)) + @BenchmarkMode(Array(Mode.Throughput)) @OutputTimeUnit(MILLISECONDS) + @Warmup(iterations = 2, time = 100, timeUnit = MILLISECONDS) + @Measurement(iterations = 2, time = 100, timeUnit = MILLISECONDS) + @Fork(2) def testFold(state: ArrayState): Unit = val builder = Vector.newBuilder[Int] state.array.foldLeft(builder)(_ += _) () @Benchmark - @BenchmarkMode(Array(Mode.SingleShotTime, Mode.Throughput)) + @BenchmarkMode(Array(Mode.Throughput)) @OutputTimeUnit(MILLISECONDS) + @Warmup(iterations = 2, time = 100, timeUnit = MILLISECONDS) + @Measurement(iterations = 2, time = 100, timeUnit = MILLISECONDS) + @Fork(2) def testArray(state: ArrayState): Unit = val builder = Vector.newBuilder[Int] var _i = 0 @@ -30,8 +35,11 @@ class ArrayBench: () @Benchmark - @BenchmarkMode(Array(Mode.SingleShotTime, Mode.Throughput)) + @BenchmarkMode(Array(Mode.Throughput)) @OutputTimeUnit(MILLISECONDS) + @Warmup(iterations = 2, time = 100, timeUnit = MILLISECONDS) + @Measurement(iterations = 2, time = 100, timeUnit = MILLISECONDS) + @Fork(2) def testForeach(state: ArrayState): Unit = val builder = Vector.newBuilder[Int] state.array.foreach(builder += _) diff --git a/tests/jmh/test b/tests/jmh/test index ab1bd708..4a02feb6 100755 --- a/tests/jmh/test +++ b/tests/jmh/test @@ -1,4 +1,7 @@ #!/usr/bin/env -S bash -e . "$(dirname "$0")"/../common.sh -bazel run :jmh +bazel run :jmh -- \ + -wi 2 -i 2 -f 2 \ + -bm thrpt \ + -tu ms