-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathCommonBenchmarkAnnotations.kt
87 lines (70 loc) · 2.53 KB
/
CommonBenchmarkAnnotations.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package kotlinx.benchmark
@Target(AnnotationTarget.FUNCTION)
expect annotation class Setup(val value: Level = Level.Trial)
expect enum class Level {
Trial, Iteration, Invocation
}
@Target(AnnotationTarget.FUNCTION)
expect annotation class TearDown(val value: Level = Level.Trial)
@Target(AnnotationTarget.FUNCTION)
expect annotation class Benchmark()
@Target(AnnotationTarget.CLASS)
expect annotation class State(val value: Scope)
expect enum class Scope {
Benchmark
}
@Target(AnnotationTarget.CLASS)
expect annotation class BenchmarkMode(vararg val value: Mode)
expect enum class Mode {
Throughput, AverageTime
}
@Target(AnnotationTarget.CLASS)
expect annotation class OutputTimeUnit(val value: BenchmarkTimeUnit)
expect enum class BenchmarkTimeUnit {
NANOSECONDS, MICROSECONDS, MILLISECONDS, SECONDS, MINUTES
}
@Suppress("REDUNDANT_ELSE_IN_WHEN")
fun BenchmarkTimeUnit.toText() = when (this) {
BenchmarkTimeUnit.NANOSECONDS -> "ns"
BenchmarkTimeUnit.MICROSECONDS -> "us"
BenchmarkTimeUnit.MILLISECONDS -> "ms"
BenchmarkTimeUnit.SECONDS -> "sec"
BenchmarkTimeUnit.MINUTES -> "min"
else -> throw UnsupportedOperationException("$this is not supported")
}
@Suppress("REDUNDANT_ELSE_IN_WHEN")
fun Mode.toText() = when (this) {
Mode.Throughput -> "thrpt"
Mode.AverageTime -> "avgt"
else -> throw UnsupportedOperationException("$this is not supported")
}
@Suppress("REDUNDANT_ELSE_IN_WHEN")
fun BenchmarkTimeUnit.toMultiplier() = when (this) {
BenchmarkTimeUnit.NANOSECONDS -> 1
BenchmarkTimeUnit.MICROSECONDS -> 1_000
BenchmarkTimeUnit.MILLISECONDS -> 1_000_000
BenchmarkTimeUnit.SECONDS -> 1_000_000_000
BenchmarkTimeUnit.MINUTES -> 60_000_000_000
else -> throw UnsupportedOperationException("$this is not supported")
}
@Suppress("REDUNDANT_ELSE_IN_WHEN")
fun BenchmarkTimeUnit.toSecondsMultiplier() = when (this) {
BenchmarkTimeUnit.NANOSECONDS -> 1.0 / 1_000_000_000
BenchmarkTimeUnit.MICROSECONDS -> 1.0 / 1_000_000
BenchmarkTimeUnit.MILLISECONDS -> 1.0 / 1_000
BenchmarkTimeUnit.SECONDS -> 1.0
BenchmarkTimeUnit.MINUTES -> 60.0
else -> throw UnsupportedOperationException("$this is not supported")
}
@Target(AnnotationTarget.CLASS)
expect annotation class Warmup(
val iterations: Int = -1
)
@Target(AnnotationTarget.CLASS)
expect annotation class Measurement(
val iterations: Int = -1,
val time: Int = -1,
val timeUnit: BenchmarkTimeUnit = BenchmarkTimeUnit.SECONDS,
val batchSize: Int = -1
)
expect annotation class Param(vararg val value: String)