Skip to content

Commit

Permalink
jmh test updated
Browse files Browse the repository at this point in the history
  • Loading branch information
anna-skrodzka committed Nov 12, 2024
1 parent 190c53d commit d68e1e5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
20 changes: 14 additions & 6 deletions tests/jmh/ArrayBench.scala
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 += _)
Expand Down
5 changes: 4 additions & 1 deletion tests/jmh/test
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit d68e1e5

Please sign in to comment.