aboutsummaryrefslogtreecommitdiff
path: root/bench
diff options
context:
space:
mode:
authorDmitry Petrashko <dmitry.petrashko@gmail.com>2014-07-23 10:46:57 +0200
committerDmitry Petrashko <dmitry.petrashko@gmail.com>2014-09-17 18:07:15 +0200
commit73324fa97e504e7a8cce5ae211efca95be4c33e9 (patch)
tree60e008fe5aa01cbded180cc3fbcd98050afb20b3 /bench
parentf0dfea49476e1b1f1d3c0f60e52e96db957dff78 (diff)
downloaddotty-73324fa97e504e7a8cce5ae211efca95be4c33e9.tar.gz
dotty-73324fa97e504e7a8cce5ae211efca95be4c33e9.tar.bz2
dotty-73324fa97e504e7a8cce5ae211efca95be4c33e9.zip
Allow converting junit test to scalameter benchmark
Lets start tracking performance! To run benchmarks execute `dotty-bench/test:run` in sbt
Diffstat (limited to 'bench')
-rw-r--r--bench/src/test/scala/TestsAsBenchmarks.scala61
1 files changed, 61 insertions, 0 deletions
diff --git a/bench/src/test/scala/TestsAsBenchmarks.scala b/bench/src/test/scala/TestsAsBenchmarks.scala
new file mode 100644
index 000000000..a078c9f78
--- /dev/null
+++ b/bench/src/test/scala/TestsAsBenchmarks.scala
@@ -0,0 +1,61 @@
+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.PerformanceTest.OnlineRegressionReport
+import org.scalameter.api._
+import org.scalameter.reporting.RegressionReporter.Tester
+
+import scala.collection.mutable.ListBuffer
+
+
+abstract class TestsToBenchmarkConverter
+(targetClass: Class[_],
+ filterAnnot: Class[_ <: java.lang.annotation.Annotation] = classOf[org.junit.Test].asInstanceOf[Class[_ <: java.lang.annotation.Annotation]])
+ extends OnlineRegressionReport {
+
+ // accept all the results, do not fail
+ override def tester: Tester = new Tester.Accepter
+
+ 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:_*)
+
+ 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 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])