Skip to content

Commit 5e0dc9c

Browse files
committed
Some improvements for dotc.Bench
1 parent 2ec5dff commit 5e0dc9c

File tree

2 files changed

+29
-13
lines changed

2 files changed

+29
-13
lines changed

compiler/src/dotty/tools/dotc/Bench.scala

+28-12
Original file line numberDiff line numberDiff line change
@@ -10,38 +10,54 @@ import scala.annotation.internal.sharable
1010
* number of compilers and run each (sequentially) a given number of times
1111
* on the same sources.
1212
*/
13-
object Bench extends Driver {
13+
object Bench extends Driver:
1414

1515
@sharable private var numRuns = 1
1616

1717
private def ntimes(n: Int)(op: => Reporter): Reporter =
1818
(0 until n).foldLeft(emptyReporter)((_, _) => op)
1919

20+
@sharable private var times: Array[Int] = _
21+
2022
override def doCompile(compiler: Compiler, fileNames: List[String])(using Context): Reporter =
21-
ntimes(numRuns) {
23+
times = new Array[Int](numRuns)
24+
var reporter: Reporter = emptyReporter
25+
for i <- 0 until numRuns do
2226
val start = System.nanoTime()
23-
val r = super.doCompile(compiler, fileNames)
24-
println(s"time elapsed: ${(System.nanoTime - start) / 1000000}ms")
25-
if (ctx.settings.Xprompt.value) {
27+
reporter = super.doCompile(compiler, fileNames)
28+
times(i) = ((System.nanoTime - start) / 1000000).toInt
29+
println(s"time elapsed: ${times(i)}ms")
30+
if ctx.settings.Xprompt.value then
2631
print("hit <return> to continue >")
2732
System.in.read()
2833
println()
29-
}
30-
r
31-
}
34+
reporter
3235

3336
def extractNumArg(args: Array[String], name: String, default: Int = 1): (Int, Array[String]) = {
3437
val pos = args indexOf name
3538
if (pos < 0) (default, args)
3639
else (args(pos + 1).toInt, (args take pos) ++ (args drop (pos + 2)))
3740
}
3841

39-
override def process(args: Array[String], rootCtx: Context): Reporter = {
42+
def reportTimes() =
43+
val best = times.sorted
44+
val measured = numRuns / 3
45+
val avgBest = best.take(measured).sum / measured
46+
val avgLast = times.reverse.take(measured).sum / measured
47+
println(s"best out of $numRuns runs: ${best(0)}")
48+
println(s"average out of best $measured: $avgBest")
49+
println(s"average out of last $measured: $avgLast")
50+
51+
override def process(args: Array[String], rootCtx: Context): Reporter =
4052
val (numCompilers, args1) = extractNumArg(args, "#compilers")
4153
val (numRuns, args2) = extractNumArg(args1, "#runs")
4254
this.numRuns = numRuns
43-
ntimes(numCompilers)(super.process(args2, rootCtx))
44-
}
45-
}
55+
var reporter: Reporter = emptyReporter
56+
for i <- 0 until numCompilers do
57+
reporter = super.process(args2, rootCtx)
58+
reportTimes()
59+
reporter
60+
61+
end Bench
4662

4763

compiler/src/dotty/tools/dotc/config/Config.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ object Config {
5050
final val checkBackendNames = false
5151

5252
/** Check that re-used type comparers are in their initialization state */
53-
final val checkTypeComparerReset = true
53+
final val checkTypeComparerReset = false
5454

5555
/** Type comparer will fail with an assert if the upper bound
5656
* of a constrained parameter becomes Nothing. This should be turned

0 commit comments

Comments
 (0)