|
| 1 | +package dotty.tools.benchmarks |
| 2 | + |
| 3 | +import org.openjdk.jmh.annotations.* |
| 4 | +import java.util.concurrent.TimeUnit.SECONDS |
| 5 | +import dotty.tools.dotc.{Driver, Run, Compiler} |
| 6 | +import dotty.tools.dotc.core.Mode |
| 7 | +import dotty.tools.dotc.core.Types.{TermRef, Type} |
| 8 | +import dotty.tools.dotc.core.Contexts.{ContextBase, Context, ctx, withMode} |
| 9 | + |
| 10 | +@Fork(value = 5) |
| 11 | +@Warmup(iterations = 5, time = 1, timeUnit = SECONDS) |
| 12 | +@Measurement(iterations = 5, time = 1, timeUnit = SECONDS) |
| 13 | +@State(Scope.Thread) |
| 14 | +class TypeOpsBenchmark: |
| 15 | + var tp: Type = null |
| 16 | + var context: Context = null |
| 17 | + |
| 18 | + @Param(Array("int", "singletonsSum", "intsSum", "deepSingletonsSum", "deepIntsSum", "singletonsIntersection", "singletonsUnion")) |
| 19 | + var valName: String = "int" |
| 20 | + |
| 21 | + @Setup(Level.Iteration) |
| 22 | + def setup(): Unit = |
| 23 | + val driver = new Driver: |
| 24 | + override def finish(compiler: Compiler, run: Run)(using Context): Unit = |
| 25 | + withMode(Mode.Printing) { |
| 26 | + val pkg = run.units(0).tpdTree.symbol |
| 27 | + tp = pkg.requiredClass("Test").requiredValueRef(valName).underlying |
| 28 | + context = ctx |
| 29 | + } |
| 30 | + super.finish(compiler, run) |
| 31 | + driver.process(Array( |
| 32 | + "-classpath", System.getProperty("BENCH_CLASS_PATH"), |
| 33 | + "-Ystop-after:typer", |
| 34 | + "tests/someTypes.scala" |
| 35 | + )) |
| 36 | + |
| 37 | + @Benchmark |
| 38 | + def isStable(): Unit = tp.isStable(using context) |
| 39 | + |
| 40 | + @Benchmark |
| 41 | + def normalized(): Unit = tp.normalized(using context) |
| 42 | + |
| 43 | + @Benchmark |
| 44 | + def simplified(): Unit = tp.simplified(using context) |
| 45 | + |
| 46 | + @Benchmark |
| 47 | + def dealias(): Unit = tp.dealias(using context) |
| 48 | + |
| 49 | + @Benchmark |
| 50 | + def widen(): Unit = tp.widen(using context) |
| 51 | + |
| 52 | + @Benchmark |
| 53 | + def atoms(): Unit = tp.atoms(using context) |
| 54 | + |
| 55 | + @Benchmark |
| 56 | + def isProvisional(): Unit = tp.isProvisional(using context) |
0 commit comments