@@ -14,24 +14,22 @@ import scala.annotation.internal.sharable
1414object Bench extends Driver :
1515
1616 @ sharable private var numRuns = 1
17-
18- private def ntimes (n : Int )(op : => Reporter ): Reporter =
19- (0 until n).foldLeft(emptyReporter)((_, _) => op)
20-
17+ @ sharable private var numCompilers = 1
18+ @ sharable private var waitAfter = - 1
19+ @ sharable private var curCompiler = 0
2120 @ sharable private var times : Array [Int ] = _
2221
2322 override def doCompile (compiler : Compiler , files : List [AbstractFile ])(using Context ): Reporter =
24- times = new Array [Int ](numRuns)
2523 var reporter : Reporter = emptyReporter
2624 for i <- 0 until numRuns do
25+ val curRun = curCompiler * numRuns + i
2726 val start = System .nanoTime()
2827 reporter = super .doCompile(compiler, files)
29- times(i ) = ((System .nanoTime - start) / 1000000 ).toInt
30- println(s " time elapsed: ${times(i )}ms " )
31- if ctx.settings.Xprompt .value then
28+ times(curRun ) = ((System .nanoTime - start) / 1000000 ).toInt
29+ println(s " time elapsed: ${times(curRun )}ms " )
30+ if ctx.settings.Xprompt .value || waitAfter == curRun + 1 then
3231 print(" hit <return> to continue >" )
3332 System .in.nn.read()
34- println()
3533 reporter
3634
3735 def extractNumArg (args : Array [String ], name : String , default : Int = 1 ): (Int , Array [String ]) = {
@@ -42,20 +40,26 @@ object Bench extends Driver:
4240
4341 def reportTimes () =
4442 val best = times.sorted
45- val measured = numRuns / 3
43+ val measured = numCompilers * numRuns / 3
4644 val avgBest = best.take(measured).sum / measured
4745 val avgLast = times.reverse.take(measured).sum / measured
48- println(s " best out of $numRuns runs: ${best(0 )}" )
46+ println(s " best out of ${numCompilers * numRuns} runs: ${best(0 )}" )
4947 println(s " average out of best $measured: $avgBest" )
5048 println(s " average out of last $measured: $avgLast" )
5149
52- override def process (args : Array [String ], rootCtx : Context ): Reporter =
50+ override def process (args : Array [String ]): Reporter =
5351 val (numCompilers, args1) = extractNumArg(args, " #compilers" )
5452 val (numRuns, args2) = extractNumArg(args1, " #runs" )
53+ val (waitAfter, args3) = extractNumArg(args2, " #wait-after" , - 1 )
54+ this .numCompilers = numCompilers
5555 this .numRuns = numRuns
56+ this .waitAfter = waitAfter
57+ this .times = new Array [Int ](numCompilers * numRuns)
5658 var reporter : Reporter = emptyReporter
57- for i <- 0 until numCompilers do
58- reporter = super .process(args2, rootCtx)
59+ curCompiler = 0
60+ while curCompiler < numCompilers do
61+ reporter = super .process(args3)
62+ curCompiler += 1
5963 reportTimes()
6064 reporter
6165
0 commit comments