aboutsummaryrefslogtreecommitdiff
path: root/bench/test/dotty/tools/benchmarks/Benchmarks.scala
blob: 04e7e25d785579091f3b5b1874d7f3721909953c (plain)
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package dotty.tools.benchmarks

import dotty.tools.StdLibSources
import org.scalameter.Key.reports._
import org.scalameter.PerformanceTest.OnlineRegressionReport
import org.scalameter.api._
import org.scalameter.{Context, History, currentContext, persistence}
import org.scalameter.reporting.RegressionReporter.Tester
import dotty.tools.dotc.CompilerTest

import scala.io.Source
import scala.reflect.io.Directory

// decorator of persitor to expose info for debugging
class DecoratorPersistor(p: Persistor) extends SerializationPersistor {

  override def load(context: Context): History = {
    val resultdir = currentContext(resultDir)
    val scope = context.scope
    val curve = context.curve
    val fileName = s"$resultdir$sep$scope.$curve.dat"

    println(s"load file $fileName")

    p.load(context)
  }

  override def save(context: Context, h: History) = {
    val resultdir = currentContext(resultDir)
    val scope = context.scope
    val curve = context.curve
    val fileName = s"$resultdir$sep$scope.$curve.dat"

    println(s"save file $fileName")

    p.save(context, h)
  }
}

object BenchTests extends OnlineRegressionReport {
  val outputDir = "../out/"

  val compiler = new CompilerTest {
    override val defaultOutputDir: String = outputDir
  }

  implicit val defaultOptions = List("-d", outputDir)
  val scala2mode = List("-language:Scala2")

  val dottyDir = "../compiler/src/dotty/"
  val testDir  = "../bench/tests/"

  val stdlibFiles = StdLibSources.whitelisted

  def stdLib = compiler.compileList("compileStdLib", stdlibFiles, "-migration" :: scala2mode)

  def dotty = compiler.compileDir(dottyDir, ".",  List("-deep", "-strict"))

  // NOTE: use `val persistor = ...` would cause persistor ignore command line options for `resultDir`
  override def persistor = new DecoratorPersistor(super.persistor)

  // accept all the results, do not fail
  override def tester: Tester = new Tester.Accepter

  // store all results
  override def historian: RegressionReporter.Historian = RegressionReporter.Historian.Complete()

  override def executor: Executor = LocalExecutor(warmer, aggregator, measurer)


  def setup =
    performance of "dotty" in {
      measure.method("stdlib") in {
        using(Gen.unit("test")) curve "stdlib" in { r => stdLib }
      }

      measure.method("dotty-src") in {
        using(Gen.unit("test")) curve "dotty-src" in { r => dotty }
      }

      val dir = Directory(testDir)
      val fileNames = dir.files.toArray.map(_.jfile.getName).filter(name => (name endsWith ".scala"))

      for (name <- fileNames) {
        measure.method(name) in {
          using(Gen.unit("test")) curve "dotty" in { r =>
            compiler.compileFile(testDir, name, extension = "")
          }
        }
      }
    }

  /** workaround to fix problem in ScalaMeter
    *
    * NOTE: Otherwise, command line options would be ignored by HTMLReporter, as
    *       the HTMLReporter uses the context of tree node, which is created via
    *       ScalaMeter DSL before command line option `-CresultDir` takes effect
    *       in `PerformanceTest.main`.
    *
    *       Following code ensures that the test tree is set up after the `-CresultDir`
    *       option takes effect.
    **/
  override def executeTests(): Boolean = {
    setup
    super.executeTests()
  }

}