-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Put TimersBench on all benchmark projects.
- Loading branch information
Showing
2 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
modules/benchmark_2_11/src/main/scala/benchmark/TimersBench.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
28
modules/benchmark_2_13/src/main/scala/benchmark/TimersBench.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |