File tree 1 file changed +46
-0
lines changed
test/benchmarks/src/main/scala/reflect/internal
1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change
1
+ package scala .reflect .internal
2
+
3
+ import org .openjdk .jmh .annotations ._
4
+ import org .openjdk .jmh .infra ._
5
+ import org .openjdk .jmh .runner .IterationType
6
+ import benchmark ._
7
+ import java .util .concurrent .TimeUnit
8
+
9
+ import scala .reflect .internal .util .BatchSourceFile
10
+
11
+ @ BenchmarkMode (Array (Mode .AverageTime ))
12
+ @ Fork (2 )
13
+ @ Threads (1 )
14
+ @ Warmup (iterations = 10 )
15
+ @ Measurement (iterations = 10 )
16
+ @ OutputTimeUnit (TimeUnit .NANOSECONDS )
17
+ @ State (Scope .Benchmark )
18
+ class SymbolBenchmark {
19
+ import scala .tools .nsc ._
20
+ var g : Global = _
21
+ var symbol : Global # Symbol = _
22
+
23
+ @ Setup (Level .Trial )
24
+ def setup (): Unit = {
25
+ val settings = new Settings ()
26
+ settings.usejavacp.value = true
27
+ settings.stopAfter.value = List (" typer" )
28
+ val global = new Global (settings)
29
+ g = global
30
+
31
+ val run = new global.Run ()
32
+ val source = g.newSourceFile(" package p1; class C { def foo: List[String] = Nil }" )
33
+ run.compileSources(source :: Nil )
34
+ val foo = global.rootMirror.getClassIfDefined(" p1.C" ).info.decl(global.newTermName(" foo" ))
35
+ symbol = foo
36
+ }
37
+
38
+ @ Benchmark def measure (bh : Blackhole ): Unit = {
39
+ val r = g.currentRun
40
+ g.phase = r.erasurePhase
41
+ bh.consume(symbol.info)
42
+ g.phase = r.typerPhase
43
+ bh.consume(symbol.info)
44
+
45
+ }
46
+ }
You can’t perform that action at this time.
0 commit comments