aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/dotty/tools/dotc/Bench.scala18
-rw-r--r--test/test/CompilerTest.scala13
-rw-r--r--tests/pos/Coder.scala1
3 files changed, 17 insertions, 15 deletions
diff --git a/src/dotty/tools/dotc/Bench.scala b/src/dotty/tools/dotc/Bench.scala
index 4ac142683..06102c7f3 100644
--- a/src/dotty/tools/dotc/Bench.scala
+++ b/src/dotty/tools/dotc/Bench.scala
@@ -28,11 +28,19 @@ object Bench extends Driver {
override def newCompiler(): Compiler = compiler
+ private def ntimes(n: Int)(op: => Reporter): Reporter =
+ (emptyReporter /: (0 until n)) ((_, _) => op)
+
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
- (emptyReporter /: (0 until numRuns))((_, _) => super.doCompile(compiler, fileNames))
+ ntimes(numRuns) {
+ val start = System.nanoTime()
+ val r = super.doCompile(compiler, fileNames)
+ println(s"time elapsed: ${(System.nanoTime - start) / 1000000}ms")
+ r
+ }
def extractNumArg(args: Array[String], name: String, default: Int = 1): (Int, Array[String]) = {
val pos = args indexOf name
@@ -40,15 +48,11 @@ object Bench extends Driver {
else (args(pos + 1).toInt, (args take pos) ++ (args drop (pos + 2)))
}
- override def main(args: Array[String]): Unit = {
+ override def process(args: Array[String]): Reporter = {
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(args2)
- println(s"time elapsed: ${(System.nanoTime - start) / 1000000}ms")
- }
+ ntimes(numCompilers)(super.process(args2))
}
}
diff --git a/test/test/CompilerTest.scala b/test/test/CompilerTest.scala
index 09112be2f..26a0b3831 100644
--- a/test/test/CompilerTest.scala
+++ b/test/test/CompilerTest.scala
@@ -10,13 +10,12 @@ class CompilerTest extends DottyTest {
def defaultOptions: List[String] = Nil
- def compileArgs(args: Array[String], xerrors: Int = 0): Unit =
- if (args.exists(_.startsWith("#")))
- Bench.main(args ++ defaultOptions)
- else {
- val nerrors = Main.process(args ++ defaultOptions).count(Reporter.ERROR.level)
- assert(nerrors == xerrors, s"Wrong # of errors. Expected: $xerrors, found: $nerrors")
- }
+ def compileArgs(args: Array[String], xerrors: Int = 0): Unit = {
+ val allArgs = args ++ defaultOptions
+ val processor = if (allArgs.exists(_.startsWith("#"))) Bench else Main
+ val nerrors = processor.process(allArgs).count(Reporter.ERROR.level)
+ assert(nerrors == xerrors, s"Wrong # of errors. Expected: $xerrors, found: $nerrors")
+ }
def compileLine(cmdLine: String, xerrors: Int = 0): Unit = compileArgs(cmdLine.split("\n"), xerrors)
diff --git a/tests/pos/Coder.scala b/tests/pos/Coder.scala
index cb6464e8b..77bbd134c 100644
--- a/tests/pos/Coder.scala
+++ b/tests/pos/Coder.scala
@@ -50,7 +50,6 @@ class Coder(words: List[String]) {
}
-/** Test code */
object Coder {
def main(args : Array[String]) : Unit = {
val coder = new Coder(List("Scala", "sobls", "Python", "Ruby", "C", "A", "rocks", "sucks", "works", "Racka"))