Skip to content

Commit a5cb5d6

Browse files
committed
Benchmark for Symbol.info
1 parent a1e2284 commit a5cb5d6

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
}

0 commit comments

Comments
 (0)