Skip to content

Commit

Permalink
Add micro benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
mbovel committed Jun 14, 2022
1 parent 12a10f2 commit 823d710
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package dotty.tools.benchmarks

import org.openjdk.jmh.annotations.*
import java.util.concurrent.TimeUnit.SECONDS
import dotty.tools.dotc.{Driver, Run, Compiler}
import dotty.tools.dotc.core.Mode
import dotty.tools.dotc.core.Types.{TermRef, Type}
import dotty.tools.dotc.core.Contexts.{ContextBase, Context, ctx, withMode}

@Fork(value = 5)
@Warmup(iterations = 5, time = 1, timeUnit = SECONDS)
@Measurement(iterations = 5, time = 1, timeUnit = SECONDS)
@State(Scope.Thread)
class TypeOpsBenchmark:
var tp: Type = null
var context: Context = null

@Param(Array("int", "singletonsSum", "intsSum", "deepSingletonsSum", "deepIntsSum", "singletonsIntersection", "singletonsUnion"))
var valName: String = "int"

@Setup(Level.Iteration)
def setup(): Unit =
val driver = new Driver:
override def finish(compiler: Compiler, run: Run)(using Context): Unit =
withMode(Mode.Printing) {
val pkg = run.units(0).tpdTree.symbol
tp = pkg.requiredClass("Test").requiredValueRef(valName).underlying
context = ctx
}
super.finish(compiler, run)
driver.process(Array(
"-classpath", System.getProperty("BENCH_CLASS_PATH"),
"-Ystop-after:typer",
"tests/someTypes.scala"
))

@Benchmark
def isStable(): Unit = tp.isStable(using context)

@Benchmark
def normalized(): Unit = tp.normalized(using context)

@Benchmark
def simplified(): Unit = tp.simplified(using context)

@Benchmark
def dealias(): Unit = tp.dealias(using context)

@Benchmark
def widen(): Unit = tp.widen(using context)

@Benchmark
def atoms(): Unit = tp.atoms(using context)

@Benchmark
def isProvisional(): Unit = tp.isProvisional(using context)
22 changes: 22 additions & 0 deletions bench-micro/tests/someTypes.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import compiletime.ops.int.+

class Test:
val int: Int = 5

val int2: Int = 6

val singletonsSum: int.type + int2.type = ???

val intsSum: Int + Int = ???

val deepSingletonsSum:
((int.type + int2.type) + (int.type + int2.type)) + ((int.type + int2.type) + (int.type + int2.type)) +
((int.type + int2.type) + (int.type + int2.type)) + ((int.type + int2.type) + (int.type + int2.type)) = ???

val deepIntsSum:
((Int + Int) + (Int + Int)) + ((Int + Int) + (Int + Int)) +
((Int + Int) + (Int + Int)) + ((Int + Int) + (Int + Int)) = ???

val singletonsIntersection: int.type & int2.type = ???

val singletonsUnion: int.type | int2.type = ???
1 change: 1 addition & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ val `scala3-tasty-inspector` = Build.`scala3-tasty-inspector`
val `scala3-language-server` = Build.`scala3-language-server`
val `scala3-bench` = Build.`scala3-bench`
val `scala3-bench-bootstrapped` = Build.`scala3-bench-bootstrapped`
val `scala3-bench-micro` = Build.`scala3-bench-micro`
val `stdlib-bootstrapped` = Build.`stdlib-bootstrapped`
val `stdlib-bootstrapped-tasty-tests` = Build.`stdlib-bootstrapped-tasty-tests`
val `tasty-core` = Build.`tasty-core`
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/plugins/Plugins.scala
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ trait Plugins {
}
else _roughPluginsList

/** Load all available plugins. Skips plugins that
/** Load all available plugins. Skips plugins that
* either have the same name as another one, or which
* define a phase name that another one does.
*/
Expand Down
4 changes: 4 additions & 0 deletions project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1247,6 +1247,10 @@ object Build {
lazy val `scala3-bench-bootstrapped` = project.in(file("bench")).asDottyBench(Bootstrapped)
lazy val `scala3-bench-run` = project.in(file("bench-run")).asDottyBench(Bootstrapped)

lazy val `scala3-bench-micro` = project.in(file("bench-micro"))
.asDottyBench(Bootstrapped)
.settings(Jmh / run / mainClass := Some("org.openjdk.jmh.Main"))

val testcasesOutputDir = taskKey[Seq[String]]("Root directory where tests classses are generated")
val testcasesSourceRoot = taskKey[String]("Root directory where tests sources are generated")
val testDocumentationRoot = taskKey[String]("Root directory where tests documentation are stored")
Expand Down
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ addSbtPlugin("com.jsuereth" % "sbt-pgp" % "2.0.0")

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

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

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

Expand Down

0 comments on commit 823d710

Please sign in to comment.