diff options
author | liu fengyun <liufengyunchina@gmail.com> | 2016-04-14 22:16:48 +0200 |
---|---|---|
committer | liu fengyun <liufengyunchina@gmail.com> | 2016-04-14 22:16:48 +0200 |
commit | 3eb30ade5c85250535ee2fbac7208b114255ccdd (patch) | |
tree | add4c73e267ba8c3d6dfcb3bf484e805650cc6df /bench | |
parent | b56f5c9620800adfaa27e359754be4b9a7aab4fe (diff) | |
download | dotty-3eb30ade5c85250535ee2fbac7208b114255ccdd.tar.gz dotty-3eb30ade5c85250535ee2fbac7208b114255ccdd.tar.bz2 dotty-3eb30ade5c85250535ee2fbac7208b114255ccdd.zip |
workaround for ScalaMeter incorrect report path
The ScalaMeter issue is reported here:
https://github.com/scalameter/scalameter/pull/163/files
The issue exists both in v0.7 and v0.6. As dotty uses v0.6 now,
use this workaround until we upgrate to a new version of ScalaMeter.
Diffstat (limited to 'bench')
-rw-r--r-- | bench/src/test/scala/TestsAsBenchmarks.scala | 62 |
1 files changed, 54 insertions, 8 deletions
diff --git a/bench/src/test/scala/TestsAsBenchmarks.scala b/bench/src/test/scala/TestsAsBenchmarks.scala index a078c9f78..95c8197ee 100644 --- a/bench/src/test/scala/TestsAsBenchmarks.scala +++ b/bench/src/test/scala/TestsAsBenchmarks.scala @@ -5,18 +5,48 @@ 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 @@ -29,15 +59,31 @@ abstract class TestsToBenchmarkConverter (name, Gen.single("test")(name).map(Request.method(targetClass, _).getRunner))}.toMap //Gen.enumeration("test")(testNames:_*) - performance of targetClass.getSimpleName config (Context(reports.resultDir -> "./tmp")) in { - for (test <- testNames) - measure.method(test) in { - using(tests(test)) curve test in { - r => - val dummy = new RunNotifier() - r.run(dummy) + 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] = { |