Skip to content

Commit b88868a

Browse files
committed
Fix NPE with unspecified TimeUnit and add more abbreviations for time units
1 parent e0a1b3c commit b88868a

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

runtime/commonMain/src/org/jetbrains/gradle/benchmarks/RunnerConfiguration.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ class RunnerConfiguration : CommandLineInterface("Client") {
3232
).map { parseTimeUnit(it) }.store()
3333

3434
private fun parseTimeUnit(text: String) = when (text) {
35-
BenchmarkTimeUnit.SECONDS.name, "s" -> BenchmarkTimeUnit.SECONDS
36-
BenchmarkTimeUnit.MICROSECONDS.name, "us" -> BenchmarkTimeUnit.MICROSECONDS
37-
BenchmarkTimeUnit.MILLISECONDS.name, "ms" -> BenchmarkTimeUnit.MILLISECONDS
38-
BenchmarkTimeUnit.NANOSECONDS.name, "ns" -> BenchmarkTimeUnit.NANOSECONDS
39-
BenchmarkTimeUnit.MINUTES.name, "m" -> BenchmarkTimeUnit.MINUTES
35+
BenchmarkTimeUnit.SECONDS.name, "s", "sec" -> BenchmarkTimeUnit.SECONDS
36+
BenchmarkTimeUnit.MICROSECONDS.name, "us", "micros" -> BenchmarkTimeUnit.MICROSECONDS
37+
BenchmarkTimeUnit.MILLISECONDS.name, "ms", "millis" -> BenchmarkTimeUnit.MILLISECONDS
38+
BenchmarkTimeUnit.NANOSECONDS.name, "ns", "nanos" -> BenchmarkTimeUnit.NANOSECONDS
39+
BenchmarkTimeUnit.MINUTES.name, "m", "min" -> BenchmarkTimeUnit.MINUTES
4040
else -> throw UnsupportedOperationException("Unknown time unit: $text")
4141
}
4242

runtime/jvmMain/src/org/jetbrains/gradle/benchmarks/jvm/JvmBenchmarkRunner.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import org.openjdk.jmh.runner.*
99
import org.openjdk.jmh.runner.format.*
1010
import org.openjdk.jmh.runner.options.*
1111
import java.io.*
12+
import java.util.concurrent.*
1213

1314
fun main(args: Array<String>) {
1415
val params = RunnerConfiguration().also { it.parse(args) }
@@ -17,7 +18,7 @@ fun main(args: Array<String>) {
1718
params.iterations?.let { jmhOptions.measurementIterations(it) }
1819
params.warmups?.let { jmhOptions.warmupIterations(it) }
1920
params.iterationTime?.let {
20-
val timeValue = TimeValue(it, params.iterationTimeUnit)
21+
val timeValue = TimeValue(it, params.iterationTimeUnit ?: TimeUnit.SECONDS)
2122
jmhOptions.warmupTime(timeValue)
2223
jmhOptions.measurementTime(timeValue)
2324
}

0 commit comments

Comments
 (0)