Skip to content

Commit 823d710

Browse files
committed
Add micro benchmarks
1 parent 12a10f2 commit 823d710

File tree

6 files changed

+85
-2
lines changed

6 files changed

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

bench-micro/tests/someTypes.scala

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import compiletime.ops.int.+
2+
3+
class Test:
4+
val int: Int = 5
5+
6+
val int2: Int = 6
7+
8+
val singletonsSum: int.type + int2.type = ???
9+
10+
val intsSum: Int + Int = ???
11+
12+
val deepSingletonsSum:
13+
((int.type + int2.type) + (int.type + int2.type)) + ((int.type + int2.type) + (int.type + int2.type)) +
14+
((int.type + int2.type) + (int.type + int2.type)) + ((int.type + int2.type) + (int.type + int2.type)) = ???
15+
16+
val deepIntsSum:
17+
((Int + Int) + (Int + Int)) + ((Int + Int) + (Int + Int)) +
18+
((Int + Int) + (Int + Int)) + ((Int + Int) + (Int + Int)) = ???
19+
20+
val singletonsIntersection: int.type & int2.type = ???
21+
22+
val singletonsUnion: int.type | int2.type = ???

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`

compiler/src/dotty/tools/dotc/plugins/Plugins.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ trait Plugins {
5151
}
5252
else _roughPluginsList
5353

54-
/** Load all available plugins. Skips plugins that
54+
/** Load all available plugins. Skips plugins that
5555
* either have the same name as another one, or which
5656
* define a phase name that another one does.
5757
*/

project/Build.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,6 +1247,10 @@ 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+
lazy val `scala3-bench-micro` = project.in(file("bench-micro"))
1251+
.asDottyBench(Bootstrapped)
1252+
.settings(Jmh / run / mainClass := Some("org.openjdk.jmh.Main"))
1253+
12501254
val testcasesOutputDir = taskKey[Seq[String]]("Root directory where tests classses are generated")
12511255
val testcasesSourceRoot = taskKey[String]("Root directory where tests sources are generated")
12521256
val testDocumentationRoot = taskKey[String]("Root directory where tests documentation are stored")

project/plugins.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ addSbtPlugin("com.jsuereth" % "sbt-pgp" % "2.0.0")
1010

1111
addSbtPlugin("org.xerial.sbt" % "sbt-pack" % "0.13")
1212

13-
addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.3.2")
13+
addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.4.3")
1414

1515
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.9.0")
1616

0 commit comments

Comments
 (0)