aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/Bench.scala
blob: 4ac14268305b5ea66f74fb806b85a2b4f377d708 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/* NSC -- new Scala compiler
 * Copyright 2005-2013 LAMP/EPFL
 * @author  Martin Odersky
 */
package dotty.tools
package dotc

import core.Contexts.Context
import reporting.Reporter

/* To do:
 *   - simplify hk types
 *   - have a second look at normalization (leave at method types if pt is method type?)
 *   - Don't open package objects from class files if they are present in source
 *   - Revise the way classes are inherited - when not followed by [...] or (...),
 *     assume the unparameterized type and forward type parameters as we do now for the synthetic head class.
 */
object Bench extends Driver {
  def resident(compiler: Compiler): Reporter = unsupported("resident") /*loop { line =>
    val command = new CompilerCommand(line split "\\s+" toList, new Settings(scalacError))
    compiler.reporter.reset()
    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 =
    if (new config.Settings.Setting.SettingDecorator[Boolean](ctx.base.settings.resident).value(ctx))
      resident(compiler)
    else
      (emptyReporter /: (0 until numRuns))((_, _) => super.doCompile(compiler, fileNames))

  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 = {
    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")
    }
  }
}