Skip to content

Commit 9f42ffa

Browse files
committed
Change Bench to give better timings under -YdetailedStats
Run stats only at last run. This allows one to warm up and JOT compile code before measurements start.
1 parent 07aefa9 commit 9f42ffa

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,12 @@ object Bench extends Driver:
2222
override def doCompile(compiler: Compiler, fileNames: List[String])(using Context): Reporter =
2323
times = new Array[Int](numRuns)
2424
var reporter: Reporter = emptyReporter
25+
val stats = ctx.settings.YdetailedStats.value
2526
for i <- 0 until numRuns do
2627
val start = System.nanoTime()
27-
reporter = super.doCompile(compiler, fileNames)
28+
reporter = inContext(ctx.fresh.setSetting(ctx.settings.YdetailedStats, stats && i == numRuns - 1)) {
29+
super.doCompile(compiler, fileNames)
30+
}
2831
times(i) = ((System.nanoTime - start) / 1000000).toInt
2932
println(s"time elapsed: ${times(i)}ms")
3033
if ctx.settings.Xprompt.value then
@@ -33,11 +36,10 @@ object Bench extends Driver:
3336
println()
3437
reporter
3538

36-
def extractNumArg(args: Array[String], name: String, default: Int = 1): (Int, Array[String]) = {
37-
val pos = args indexOf name
38-
if (pos < 0) (default, args)
39-
else (args(pos + 1).toInt, (args take pos) ++ (args drop (pos + 2)))
40-
}
39+
def extractNumArg(args: Array[String], name: String, default: Int = 1): (Int, Array[String]) =
40+
val pos = args.indexOf(name)
41+
if pos < 0 then (default, args)
42+
else (args(pos + 1).toInt, args.take(pos) ++ args.drop(pos + 2))
4143

4244
def reportTimes() =
4345
val best = times.sorted

0 commit comments

Comments
 (0)