Skip to content

Commit

Permalink
Add help message for bench-run
Browse files Browse the repository at this point in the history
  • Loading branch information
Antoine Brunner committed Dec 3, 2019
1 parent f9bbdcb commit 358ea0e
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 4 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
29 changes: 25 additions & 4 deletions bench-run/src/main/scala/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,20 @@ import scala.io.Source

object Bench {
def main(args: Array[String]): Unit = {
if (args.contains("--help")) {
printUsage()
return
}

val (intArgs, args1) = args.span(x => try { x.toInt; true } catch { case _: Throwable => false } )

val warmup = if (intArgs.length > 0) intArgs(0).toInt else 20
val iterations = if (intArgs.length > 1) intArgs(1).toInt else 20
val forks = if (intArgs.length > 2) intArgs(2).toInt else 1

if (args1.isEmpty) {
println("You should specify which benchmarks to run.")
println("Error: no benchmark was specified.")
printUsage()
return
}

Expand All @@ -36,16 +42,16 @@ object Bench {
.resultFormat(ResultFormatType.CSV)

if (args1.length > 1 && args1(1) != "--") {
for ((param, values) <- paramsFromFile(args1(1)))
for ((param, values) <- paramsFromFile("inputs/" ++ args1(1)))
builder = builder.param(param, values: _*)
}

if (args1.length > 2) {
builder = builder.result(args1(2))
}

val runner = new Runner(builder.build) // full access to all JMH features, you can also provide a custom output Format here
runner.run // actually run the benchmarks
val runner = new Runner(builder.build)
runner.run
}

def paramsFromFile(file: String): Array[(String, Array[String])] = {
Expand All @@ -54,4 +60,19 @@ object Bench {
(param, values split ',')
}
}

def printUsage(): Unit = {
println()
println("Usage:")
println()
println("dotty-bench-run/jmh:run [<warmup>] [<iterations>] [<forks>] <regexp> [<input>|--] [<output>]")
println()
println("warmup: warmup iterations. defaults to 20.")
println("iterations: benchmark iterations. defaults to 20.")
println("forks: number of forks. defaults to 1.")
println("regexp: regular expression that selects which benchmarks to run.")
println("input: input vector file. each line should have format \'<paramName>: <comma-separated-values>\'")
println("output: output file for the results of benchmarks.")
println()
}
}

0 comments on commit 358ea0e

Please sign in to comment.