aboutsummaryrefslogtreecommitdiff
path: root/compiler/src/dotty/tools/dotc/Bench.scala
diff options
context:
space:
mode:
authorFelix Mulder <felix.mulder@gmail.com>2016-11-02 11:08:28 +0100
committerGuillaume Martres <smarter@ubuntu.com>2016-11-22 01:35:07 +0100
commit8a61ff432543a29234193cd1f7c14abd3f3d31a0 (patch)
treea8147561d307af862c295cfc8100d271063bb0dd /compiler/src/dotty/tools/dotc/Bench.scala
parent6a455fe6da5ff9c741d91279a2dc6fe2fb1b472f (diff)
downloaddotty-8a61ff432543a29234193cd1f7c14abd3f3d31a0.tar.gz
dotty-8a61ff432543a29234193cd1f7c14abd3f3d31a0.tar.bz2
dotty-8a61ff432543a29234193cd1f7c14abd3f3d31a0.zip
Move compiler and compiler tests to compiler dir
Diffstat (limited to 'compiler/src/dotty/tools/dotc/Bench.scala')
-rw-r--r--compiler/src/dotty/tools/dotc/Bench.scala46
1 files changed, 46 insertions, 0 deletions
diff --git a/compiler/src/dotty/tools/dotc/Bench.scala b/compiler/src/dotty/tools/dotc/Bench.scala
new file mode 100644
index 000000000..56b6dabbe
--- /dev/null
+++ b/compiler/src/dotty/tools/dotc/Bench.scala
@@ -0,0 +1,46 @@
+/* NSC -- new Scala compiler
+ * Copyright 2005-2013 LAMP/EPFL
+ * @author Martin Odersky
+ */
+package dotty.tools
+package dotc
+
+import core.Contexts.Context
+import reporting.Reporter
+
+/** A main class for running compiler benchmarks. Can instantiate a given
+ * number of compilers and run each (sequentially) a given number of times
+ * on the same sources.
+ */
+object Bench extends Driver {
+
+ @sharable private var numRuns = 1
+
+ def newCompiler(implicit ctx: Context): Compiler = new 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 =
+ 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
+ if (pos < 0) (default, args)
+ else (args(pos + 1).toInt, (args take pos) ++ (args drop (pos + 2)))
+ }
+
+ override def process(args: Array[String], rootCtx: Context): Reporter = {
+ val (numCompilers, args1) = extractNumArg(args, "#compilers")
+ val (numRuns, args2) = extractNumArg(args1, "#runs")
+ this.numRuns = numRuns
+ ntimes(numCompilers)(super.process(args2, rootCtx))
+ }
+}
+
+