Skip to content

Commit 5838fda

Browse files
committed
Merge pull request #1229 from dotty-staging/bench
[do not merge] remove magic with benchmark tests
2 parents fabe697 + b5ac5de commit 5838fda

File tree

2 files changed

+40
-46
lines changed

2 files changed

+40
-46
lines changed
Lines changed: 33 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
package dotty.tools.benchmarks
22

3-
import java.lang.annotation.Annotation
4-
import java.lang.reflect.Method
53

6-
import org.junit.runner.Request
7-
import org.junit.runner.notification.RunNotifier
84
import org.scalameter.Key.reports._
95
import org.scalameter.PerformanceTest.OnlineRegressionReport
106
import org.scalameter.api._
11-
import org.scalameter.{Context, History, persistence, currentContext}
7+
import org.scalameter.{Context, History, currentContext, persistence}
128
import org.scalameter.reporting.RegressionReporter.Tester
9+
import test.CompilerTest
1310

14-
import scala.collection.mutable.ListBuffer
11+
import scala.io.Source
1512

1613
// decorator of persitor to expose info for debugging
1714
class DecoratorPersistor(p: Persistor) extends SerializationPersistor {
@@ -39,10 +36,28 @@ class DecoratorPersistor(p: Persistor) extends SerializationPersistor {
3936
}
4037
}
4138

42-
abstract class TestsToBenchmarkConverter
43-
(targetClass: Class[_],
44-
filterAnnot: Class[_ <: java.lang.annotation.Annotation] = classOf[org.junit.Test].asInstanceOf[Class[_ <: java.lang.annotation.Annotation]])
45-
extends OnlineRegressionReport {
39+
object BenchTests extends OnlineRegressionReport {
40+
val outputDir = "./out/"
41+
42+
val compiler = new CompilerTest {
43+
override val defaultOutputDir: String = outputDir
44+
}
45+
46+
implicit val defaultOptions = List("-d", outputDir)
47+
val scala2mode = List("-language:Scala2")
48+
49+
val dottyDir = "./src/dotty/"
50+
51+
val stdlibFiles = Source.fromFile("./test/dotc/scala-collections.whitelist", "UTF8").getLines()
52+
.map(_.trim) // allow identation
53+
.filter(!_.startsWith("#")) // allow comment lines prefixed by #
54+
.map(_.takeWhile(_ != '#').trim) // allow comments in the end of line
55+
.filter(_.nonEmpty)
56+
.toList
57+
58+
def stdLib = compiler.compileList("compileStdLib", stdlibFiles, "-migration" :: scala2mode)
59+
60+
def dotty = compiler.compileDir(dottyDir, ".", List("-deep", "-strict"))
4661

4762
// NOTE: use `val persistor = ...` would cause persistor ignore command line options for `resultDir`
4863
override def persistor = new DecoratorPersistor(super.persistor)
@@ -54,24 +69,17 @@ abstract class TestsToBenchmarkConverter
5469
override def historian: RegressionReporter.Historian = RegressionReporter.Historian.Complete()
5570

5671
override def executor: Executor = LocalExecutor(warmer, aggregator, measurer)
57-
val testNames = getMethodsAnnotatedWith(targetClass, filterAnnot).map(_.getName).sorted
58-
5972

60-
val tests = testNames.map{name =>
61-
val runner = Request.method(targetClass, name).getRunner
62-
(name, Gen.single("test")(name).map(Request.method(targetClass, _).getRunner))}.toMap
63-
//Gen.enumeration("test")(testNames:_*)
6473

6574
def setup =
66-
performance of targetClass.getSimpleName in {
67-
for (test <- testNames)
68-
measure.method(test) in {
69-
using(tests(test)) curve test in {
70-
r =>
71-
val dummy = new RunNotifier()
72-
r.run(dummy)
73-
}
74-
}
75+
performance of "dotty" in {
76+
measure.method("stdlib") in {
77+
using(Gen.unit("test")) curve "stdlib" in { r => stdLib }
78+
}
79+
80+
measure.method("dotty-src") in {
81+
using(Gen.unit("test")) curve "dotty-src" in { r => dotty }
82+
}
7583
}
7684

7785
/** workaround to fix problem in ScalaMeter
@@ -89,22 +97,4 @@ abstract class TestsToBenchmarkConverter
8997
super.executeTests()
9098
}
9199

92-
def getMethodsAnnotatedWith(clazz: Class[_], annotation: Class[_ <: java.lang.annotation.Annotation]): List[Method] = {
93-
val methods = ListBuffer[Method]()
94-
var klass: Class[_] = clazz
95-
while (klass ne classOf[AnyRef]) {
96-
val allMethods = klass.getDeclaredMethods
97-
import scala.collection.JavaConversions._
98-
for (method <- allMethods) {
99-
if (annotation == null || method.isAnnotationPresent(annotation)) {
100-
val annotInstance: Annotation = method.getAnnotation(annotation)
101-
methods.add(method)
102-
}
103-
}
104-
klass = klass.getSuperclass
105-
}
106-
methods.toList
107-
}
108100
}
109-
110-
object dotcTests extends TestsToBenchmarkConverter(classOf[dotc.tests])

project/Build.scala

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ object DottyBuild extends Build {
1313

1414
val JENKINS_BUILD = "dotty.jenkins.build"
1515

16+
val scalaCompiler = "me.d-d" % "scala-compiler" % "2.11.5-20160322-171045-e19b30b3cd"
17+
1618
val agentOptions = List(
1719
// "-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005"
1820
// "-agentpath:/home/dark/opt/yjp-2013-build-13072/bin/linux-x86-64/libyjpagent.so"
@@ -81,7 +83,7 @@ object DottyBuild extends Build {
8183
com.typesafe.sbteclipse.plugin.EclipsePlugin.EclipseKeys.withSource := true,
8284

8385
// get libraries onboard
84-
partestDeps := Seq("me.d-d" % "scala-compiler" % "2.11.5-20160322-171045-e19b30b3cd",
86+
partestDeps := Seq(scalaCompiler,
8587
"org.scala-lang" % "scala-reflect" % scalaVersion.value,
8688
"org.scala-lang" % "scala-library" % scalaVersion.value % "test"),
8789
libraryDependencies ++= partestDeps.value,
@@ -242,8 +244,10 @@ object DottyBuild extends Build {
242244

243245
baseDirectory in (Test,run) := (baseDirectory in dotty).value,
244246

245-
libraryDependencies ++= Seq("com.storm-enroute" %% "scalameter" % "0.6" % Test,
246-
"com.novocode" % "junit-interface" % "0.11"),
247+
libraryDependencies ++= Seq(
248+
scalaCompiler % Test,
249+
"com.storm-enroute" %% "scalameter" % "0.6" % Test
250+
),
247251

248252
fork in Test := true,
249253
parallelExecution in Test := false,

0 commit comments

Comments
 (0)