Skip to content

[do not merge] remove magic with benchmark tests #1229

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
package dotty.tools.benchmarks

import java.lang.annotation.Annotation
import java.lang.reflect.Method

import org.junit.runner.Request
import org.junit.runner.notification.RunNotifier
import org.scalameter.Key.reports._
import org.scalameter.PerformanceTest.OnlineRegressionReport
import org.scalameter.api._
import org.scalameter.{Context, History, persistence, currentContext}
import org.scalameter.{Context, History, currentContext, persistence}
import org.scalameter.reporting.RegressionReporter.Tester
import test.CompilerTest

import scala.collection.mutable.ListBuffer
import scala.io.Source

// decorator of persitor to expose info for debugging
class DecoratorPersistor(p: Persistor) extends SerializationPersistor {
Expand Down Expand Up @@ -39,10 +36,28 @@ class DecoratorPersistor(p: Persistor) extends SerializationPersistor {
}
}

abstract class TestsToBenchmarkConverter
(targetClass: Class[_],
filterAnnot: Class[_ <: java.lang.annotation.Annotation] = classOf[org.junit.Test].asInstanceOf[Class[_ <: java.lang.annotation.Annotation]])
extends OnlineRegressionReport {
object BenchTests extends OnlineRegressionReport {
val outputDir = "./out/"

val compiler = new CompilerTest {
override val defaultOutputDir: String = outputDir
}

implicit val defaultOptions = List("-d", outputDir)
val scala2mode = List("-language:Scala2")

val dottyDir = "./src/dotty/"

val stdlibFiles = Source.fromFile("./test/dotc/scala-collections.whitelist", "UTF8").getLines()
.map(_.trim) // allow identation
.filter(!_.startsWith("#")) // allow comment lines prefixed by #
.map(_.takeWhile(_ != '#').trim) // allow comments in the end of line
.filter(_.nonEmpty)
.toList

def stdLib = compiler.compileList("compileStdLib", stdlibFiles, "-migration" :: scala2mode)

def dotty = compiler.compileDir(dottyDir, ".", List("-deep", "-strict"))

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

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


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

def setup =
performance of targetClass.getSimpleName in {
for (test <- testNames)
measure.method(test) in {
using(tests(test)) curve test in {
r =>
val dummy = new RunNotifier()
r.run(dummy)
}
}
performance of "dotty" in {
measure.method("stdlib") in {
using(Gen.unit("test")) curve "stdlib" in { r => stdLib }
}

measure.method("dotty-src") in {
using(Gen.unit("test")) curve "dotty-src" in { r => dotty }
}
}

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

def getMethodsAnnotatedWith(clazz: Class[_], annotation: Class[_ <: java.lang.annotation.Annotation]): List[Method] = {
val methods = ListBuffer[Method]()
var klass: Class[_] = clazz
while (klass ne classOf[AnyRef]) {
val allMethods = klass.getDeclaredMethods
import scala.collection.JavaConversions._
for (method <- allMethods) {
if (annotation == null || method.isAnnotationPresent(annotation)) {
val annotInstance: Annotation = method.getAnnotation(annotation)
methods.add(method)
}
}
klass = klass.getSuperclass
}
methods.toList
}
}

object dotcTests extends TestsToBenchmarkConverter(classOf[dotc.tests])
10 changes: 7 additions & 3 deletions project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ object DottyBuild extends Build {

val JENKINS_BUILD = "dotty.jenkins.build"

val scalaCompiler = "me.d-d" % "scala-compiler" % "2.11.5-20160322-171045-e19b30b3cd"

val agentOptions = List(
// "-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005"
// "-agentpath:/home/dark/opt/yjp-2013-build-13072/bin/linux-x86-64/libyjpagent.so"
Expand Down Expand Up @@ -81,7 +83,7 @@ object DottyBuild extends Build {
com.typesafe.sbteclipse.plugin.EclipsePlugin.EclipseKeys.withSource := true,

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

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

libraryDependencies ++= Seq("com.storm-enroute" %% "scalameter" % "0.6" % Test,
"com.novocode" % "junit-interface" % "0.11"),
libraryDependencies ++= Seq(
scalaCompiler % Test,
"com.storm-enroute" %% "scalameter" % "0.6" % Test
),

fork in Test := true,
parallelExecution in Test := false,
Expand Down