Skip to content

Commit 9ca8891

Browse files
committed
Add micro benchmarks
1 parent a25960e commit 9ca8891

File tree

4 files changed

+59
-0
lines changed

4 files changed

+59
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package dotty.tools.benchmarks
2+
3+
import org.openjdk.jmh.annotations.*
4+
import dotty.tools.dotc.{Driver, Run, Compiler}
5+
import dotty.tools.dotc.core.{Mode}
6+
import dotty.tools.dotc.core.Contexts.{ContextBase, Context, ctx}
7+
import dotty.tools.dotc.ast.tpd
8+
import dotty.tools.dotc.ast.tpd.*
9+
import dotty.tools.dotc.core.Types.{TermRef, Type}
10+
import dotty.tools.dotc.core.Types.NoPrefix
11+
import dotty.tools.dotc.core.Flags
12+
13+
@State(Scope.Thread)
14+
class IsStable:
15+
var pkg: tpd.Tree = null
16+
var context: Context = null
17+
var tp: Type = null
18+
19+
class GetTreeDriver extends Driver:
20+
override def finish(compiler: Compiler, run: Run)(using Context): Unit =
21+
pkg = run.units(0).tpdTree
22+
context = ctx
23+
super.finish(compiler, run)
24+
25+
@Param(Array("int", "deepSumUnstable", "deepSumStable"))
26+
var valName: String = "int"
27+
28+
@Setup(Level.Iteration)
29+
def setup() =
30+
val args = Array(
31+
"-classpath", System.getProperty("BENCH_CLASS_PATH"),
32+
"-Ystop-after:typer",
33+
"tests/isStable.scala")
34+
GetTreeDriver().process(args)
35+
given Context = context.withModeBits(Mode.Printing)
36+
tp = pkg.symbol.requiredClass("Test").requiredValueRef(valName).underlying
37+
()
38+
39+
@Benchmark
40+
def isStableBenchmark() =
41+
given Context = context.withModeBits(Mode.Printing)
42+
tp.isStable
43+
()

bench-micro/tests/isStable.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import compiletime.ops.int.+
2+
3+
class Test:
4+
val int: Int = 5
5+
val deepSumStable:
6+
((int.type + int.type) + (int.type + int.type)) + ((int.type + int.type) + (int.type + int.type)) +
7+
((int.type + int.type) + (int.type + int.type)) + ((int.type + int.type) + (int.type + int.type)) = ???
8+
val deepSumUnstable:
9+
((Int + Int) + (Int + Int)) + ((Int + Int) + (Int + Int)) +
10+
((Int + Int) + (Int + Int)) + ((Int + Int) + (Int + Int)) = ???

build.sbt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ val `scala3-tasty-inspector` = Build.`scala3-tasty-inspector`
1313
val `scala3-language-server` = Build.`scala3-language-server`
1414
val `scala3-bench` = Build.`scala3-bench`
1515
val `scala3-bench-bootstrapped` = Build.`scala3-bench-bootstrapped`
16+
val `scala3-bench-micro` = Build.`scala3-bench-micro`
1617
val `stdlib-bootstrapped` = Build.`stdlib-bootstrapped`
1718
val `stdlib-bootstrapped-tasty-tests` = Build.`stdlib-bootstrapped-tasty-tests`
1819
val `tasty-core` = Build.`tasty-core`

project/Build.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,6 +1247,11 @@ object Build {
12471247
lazy val `scala3-bench-bootstrapped` = project.in(file("bench")).asDottyBench(Bootstrapped)
12481248
lazy val `scala3-bench-run` = project.in(file("bench-run")).asDottyBench(Bootstrapped)
12491249

1250+
1251+
lazy val `scala3-bench-micro` = project.in(file("bench-micro"))
1252+
.asDottyBench(NonBootstrapped)
1253+
.settings(Jmh / run / mainClass := Some("org.openjdk.jmh.Main"))
1254+
12501255
val testcasesOutputDir = taskKey[Seq[String]]("Root directory where tests classses are generated")
12511256
val testcasesSourceRoot = taskKey[String]("Root directory where tests sources are generated")
12521257
val testDocumentationRoot = taskKey[String]("Root directory where tests documentation are stored")

0 commit comments

Comments
 (0)