Skip to content

Commit 1682983

Browse files
committed
New benchmark class that allows tuning for #compilers and #runs
by command line options like #compilers 3 #runs 10 This would create one after another 3 compiler instances and perform 10 runs in each.
1 parent 01fc181 commit 1682983

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

src/dotty/tools/dotc/Bench.scala

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,31 @@ object Bench extends Driver {
2222
new compiler.Run() compile command.files
2323
}*/
2424

25+
private var numRuns = 1
26+
2527
lazy val compiler = new Compiler
2628

2729
override def newCompiler(): Compiler = compiler
2830

29-
override def doCompile(compiler: Compiler, fileNames: List[String])(implicit ctx: Context): Reporter = {
31+
override def doCompile(compiler: Compiler, fileNames: List[String])(implicit ctx: Context): Reporter =
3032
if (new config.Settings.Setting.SettingDecorator[Boolean](ctx.base.settings.resident).value(ctx))
3133
resident(compiler)
3234
else
33-
super.doCompile(compiler, fileNames)
34-
}
35+
(emptyReporter /: (0 until numRuns))((_, _) => super.doCompile(compiler, fileNames))
3536

36-
val N = 10
37+
def extractNumArg(args: Array[String], name: String, default: Int = 1): (Int, Array[String]) = {
38+
val pos = args indexOf name
39+
if (pos < 0) (default, args)
40+
else (args(pos + 1).toInt, (args take pos) ++ (args drop (pos + 2)))
41+
}
3742

3843
override def main(args: Array[String]): Unit = {
39-
for (i <- 0 until N) {
44+
val (numCompilers, args1) = extractNumArg(args, "#compilers")
45+
val (numRuns, args2) = extractNumArg(args1, "#runs")
46+
this.numRuns = numRuns
47+
for (i <- 0 until numCompilers) {
4048
val start = System.nanoTime()
41-
process(args)
49+
process(args2)
4250
println(s"time elapsed: ${(System.nanoTime - start) / 1000000}ms")
4351
}
4452
}

src/dotty/tools/dotc/Driver.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ abstract class Driver extends DotClass {
1111

1212
protected def newCompiler(): Compiler
1313

14-
protected def emptyReporter = new StoreReporter
14+
protected def emptyReporter: Reporter = new StoreReporter
1515

1616
protected def doCompile(compiler: Compiler, fileNames: List[String])(implicit ctx: Context): Reporter =
1717
if (fileNames.nonEmpty) {

0 commit comments

Comments
 (0)