Skip to content

Commit

Permalink
Merge pull request #81 from tarao/ci-benchmark
Browse files Browse the repository at this point in the history
CI for benchmarks
  • Loading branch information
tarao authored Feb 29, 2024
2 parents 73d122c + a994539 commit ef49fa2
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 1 deletion.
31 changes: 31 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,37 @@ jobs:
modules-ignore: benchmark_3_3 benchmark_2_11_2.11 rootjs_3 docs_3 benchmark_2_13_2.13 rootjvm_3 rootnative_3
configs-ignore: test scala-tool scala-doc-tool test-internal

build-benchmark:
name: Build and Test Benchmarks
strategy:
matrix:
os: [ubuntu-latest]
java: [temurin@11]
project: [benchmark_2_11, benchmark_2_13, benchmark_3]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout current branch (fast)
uses: actions/checkout@v4

- name: Setup Java (temurin@11)
id: setup-java-temurin-11
if: matrix.java == 'temurin@11'
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 11
cache: sbt

- name: sbt update
if: matrix.java == 'temurin@11' && steps.setup-java-temurin-11.outputs.cache-hit == 'false'
run: sbt +update

- name: sbt update (project)
run: sbt 'project ${{ matrix.project }}' update

- name: Test
run: sbt 'project ${{ matrix.project }}' 'Jmh / run TimersBench'

coverage:
name: Generate coverage report
strategy:
Expand Down
29 changes: 28 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ ThisBuild / githubWorkflowJavaVersions := Seq(
JavaSpec.temurin("11"),
JavaSpec.temurin("17"),
)
val BenchmarkJavaVersion = JavaSpec.temurin("11")

val circeVersion = "0.14.6"
val scalaTestVersion = "3.2.18"
Expand Down Expand Up @@ -141,7 +142,8 @@ lazy val benchmark_2_11 = (project in file("modules/benchmark_2_11"))
.enablePlugins(JmhPlugin)
.enablePlugins(NoPublishPlugin)
.settings(
scalaVersion := Scala_2_11,
scalaVersion := Scala_2_11,
tlFatalWarnings := false,
Compile / run / javaOptions ++= Seq(
"-Xss10m",
),
Expand All @@ -151,6 +153,31 @@ lazy val benchmark_2_11 = (project in file("modules/benchmark_2_11"))
),
)

ThisBuild / githubWorkflowAddedJobs ++= Seq(
WorkflowJob(
id = "build-benchmark",
name = "Build and Test Benchmarks",
javas = List(BenchmarkJavaVersion),
scalas = Nil,
matrixAdds = Map(
"project" -> List(benchmark_2_11.id, benchmark_2_13.id, benchmark_3.id),
),
steps = List(WorkflowStep.Checkout) ++ WorkflowStep.SetupJava(
List(BenchmarkJavaVersion),
) ++ githubWorkflowGeneratedCacheSteps.value ++ List(
WorkflowStep.Run(
name = Some("sbt update (project)"),
commands = List("sbt 'project ${{ matrix.project }}' update"),
),
WorkflowStep.Run(
name = Some("Test"),
commands =
List("sbt 'project ${{ matrix.project }}' 'Jmh / run TimersBench'"),
),
),
),
)

ThisBuild / githubWorkflowTargetBranches := Seq("master")
ThisBuild / tlCiReleaseBranches := Seq() // publish only tags

Expand Down
28 changes: 28 additions & 0 deletions modules/benchmark_2_11/src/main/scala/benchmark/TimersBench.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package benchmark

import java.util.concurrent.TimeUnit;
import org.openjdk.jmh.annotations._

@BenchmarkMode(Array(Mode.AverageTime))
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@Warmup(iterations = 5, time = 100, timeUnit = TimeUnit.MILLISECONDS)
@Measurement(iterations = 5, time = 100, timeUnit = TimeUnit.MILLISECONDS)
@Fork(5)
@State(Scope.Thread)
class TimersBench {
var lastValue: Long = 0

@Benchmark
def latencyNanotime(): Long = System.nanoTime()

@Benchmark
def granularityNanotime(): Long = {
var cur: Long = 0
while ({
cur = System.nanoTime()
cur == lastValue
})()
lastValue = cur
cur
}
}
28 changes: 28 additions & 0 deletions modules/benchmark_2_13/src/main/scala/benchmark/TimersBench.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package benchmark

import java.util.concurrent.TimeUnit;
import org.openjdk.jmh.annotations.*

@BenchmarkMode(Array(Mode.AverageTime))
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@Warmup(iterations = 5, time = 100, timeUnit = TimeUnit.MILLISECONDS)
@Measurement(iterations = 5, time = 100, timeUnit = TimeUnit.MILLISECONDS)
@Fork(5)
@State(Scope.Thread)
class TimersBench {
var lastValue: Long = 0

@Benchmark
def latencyNanotime(): Long = System.nanoTime()

@Benchmark
def granularityNanotime(): Long = {
var cur: Long = 0
while ({
cur = System.nanoTime()
cur == lastValue
})()
lastValue = cur
cur
}
}

0 comments on commit ef49fa2

Please sign in to comment.