From 9096d0833c3e8cc713a4d035e611b5c593db2f6d Mon Sep 17 00:00:00 2001 From: liu fengyun Date: Mon, 30 May 2016 10:02:57 +0200 Subject: remove magic with benchmark tests - remove dependence on junit - remove `pos` tests - merge all dotc related tests to a single `dotty` test - remove `Ycheck:all` --- bench/src/test/scala/Benchmarks.scala | 100 ++++++++++++++++++++++++ bench/src/test/scala/TestsAsBenchmarks.scala | 110 --------------------------- 2 files changed, 100 insertions(+), 110 deletions(-) create mode 100644 bench/src/test/scala/Benchmarks.scala delete mode 100644 bench/src/test/scala/TestsAsBenchmarks.scala (limited to 'bench') diff --git a/bench/src/test/scala/Benchmarks.scala b/bench/src/test/scala/Benchmarks.scala new file mode 100644 index 000000000..b85f95d6e --- /dev/null +++ b/bench/src/test/scala/Benchmarks.scala @@ -0,0 +1,100 @@ +package dotty.tools.benchmarks + + +import org.scalameter.Key.reports._ +import org.scalameter.PerformanceTest.OnlineRegressionReport +import org.scalameter.api._ +import org.scalameter.{Context, History, currentContext, persistence} +import org.scalameter.reporting.RegressionReporter.Tester +import test.CompilerTest + +import scala.io.Source + +// decorator of persitor to expose info for debugging +class DecoratorPersistor(p: Persistor) extends SerializationPersistor { + + override def load(context: Context): History = { + val resultdir = currentContext(resultDir) + val scope = context.scope + val curve = context.curve + val fileName = s"$resultdir$sep$scope.$curve.dat" + + println(s"load file $fileName") + + p.load(context) + } + + override def save(context: Context, h: History) = { + val resultdir = currentContext(resultDir) + val scope = context.scope + val curve = context.curve + val fileName = s"$resultdir$sep$scope.$curve.dat" + + println(s"save file $fileName") + + p.save(context, h) + } +} + +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) + + // accept all the results, do not fail + override def tester: Tester = new Tester.Accepter + + // store all results + override def historian: RegressionReporter.Historian = RegressionReporter.Historian.Complete() + + override def executor: Executor = LocalExecutor(warmer, aggregator, measurer) + + + def setup = + 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 + * + * NOTE: Otherwise, command line options would be ignored by HTMLReporter, as + * the HTMLReporter uses the context of tree node, which is created via + * ScalaMeter DSL before command line option `-CresultDir` takes effect + * in `PerformanceTest.main`. + * + * Following code ensures that the test tree is set up after the `-CresultDir` + * option takes effect. + **/ + override def executeTests(): Boolean = { + setup + super.executeTests() + } + +} diff --git a/bench/src/test/scala/TestsAsBenchmarks.scala b/bench/src/test/scala/TestsAsBenchmarks.scala deleted file mode 100644 index cac34640f..000000000 --- a/bench/src/test/scala/TestsAsBenchmarks.scala +++ /dev/null @@ -1,110 +0,0 @@ -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.reporting.RegressionReporter.Tester - -import scala.collection.mutable.ListBuffer - -// decorator of persitor to expose info for debugging -class DecoratorPersistor(p: Persistor) extends SerializationPersistor { - - override def load(context: Context): History = { - val resultdir = currentContext(resultDir) - val scope = context.scope - val curve = context.curve - val fileName = s"$resultdir$sep$scope.$curve.dat" - - println(s"load file $fileName") - - p.load(context) - } - - override def save(context: Context, h: History) = { - val resultdir = currentContext(resultDir) - val scope = context.scope - val curve = context.curve - val fileName = s"$resultdir$sep$scope.$curve.dat" - - println(s"save file $fileName") - - p.save(context, h) - } -} - -abstract class TestsToBenchmarkConverter -(targetClass: Class[_], - filterAnnot: Class[_ <: java.lang.annotation.Annotation] = classOf[org.junit.Test].asInstanceOf[Class[_ <: java.lang.annotation.Annotation]]) - extends OnlineRegressionReport { - - // NOTE: use `val persistor = ...` would cause persistor ignore command line options for `resultDir` - override def persistor = new DecoratorPersistor(super.persistor) - - // accept all the results, do not fail - override def tester: Tester = new Tester.Accepter - - // store all results - 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) - } - } - } - - /** workaround to fix problem in ScalaMeter - * - * NOTE: Otherwise, command line options would be ignored by HTMLReporter, as - * the HTMLReporter uses the context of tree node, which is created via - * ScalaMeter DSL before command line option `-CresultDir` takes effect - * in `PerformanceTest.main`. - * - * Following code ensures that the test tree is set up after the `-CresultDir` - * option takes effect. - **/ - override def executeTests(): Boolean = { - setup - 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]) -- cgit v1.2.3