From 16829831dcf417d7af409ecdd965b59b886921cd Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 3 Feb 2014 17:05:10 +0100 Subject: 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. --- src/dotty/tools/dotc/Bench.scala | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'src/dotty/tools/dotc/Bench.scala') diff --git a/src/dotty/tools/dotc/Bench.scala b/src/dotty/tools/dotc/Bench.scala index 1fca7a2bb..4ac142683 100644 --- a/src/dotty/tools/dotc/Bench.scala +++ b/src/dotty/tools/dotc/Bench.scala @@ -22,23 +22,31 @@ object Bench extends Driver { new compiler.Run() compile command.files }*/ + private var numRuns = 1 + lazy val compiler = new Compiler override def newCompiler(): Compiler = compiler - override def doCompile(compiler: Compiler, fileNames: List[String])(implicit ctx: Context): Reporter = { + override def doCompile(compiler: Compiler, fileNames: List[String])(implicit ctx: Context): Reporter = if (new config.Settings.Setting.SettingDecorator[Boolean](ctx.base.settings.resident).value(ctx)) resident(compiler) else - super.doCompile(compiler, fileNames) - } + (emptyReporter /: (0 until numRuns))((_, _) => super.doCompile(compiler, fileNames)) - val N = 10 + def extractNumArg(args: Array[String], name: String, default: Int = 1): (Int, Array[String]) = { + val pos = args indexOf name + if (pos < 0) (default, args) + else (args(pos + 1).toInt, (args take pos) ++ (args drop (pos + 2))) + } override def main(args: Array[String]): Unit = { - for (i <- 0 until N) { + val (numCompilers, args1) = extractNumArg(args, "#compilers") + val (numRuns, args2) = extractNumArg(args1, "#runs") + this.numRuns = numRuns + for (i <- 0 until numCompilers) { val start = System.nanoTime() - process(args) + process(args2) println(s"time elapsed: ${(System.nanoTime - start) / 1000000}ms") } } -- cgit v1.2.3