Skip to content

Commit

Permalink
Put TimersBench on all benchmark projects.
Browse files Browse the repository at this point in the history
  • Loading branch information
tarao committed Feb 28, 2024
1 parent 73d122c commit 31fc7dc
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
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 31fc7dc

Please sign in to comment.