1
1
package dotty .tools .benchmarks
2
2
3
- import java .lang .annotation .Annotation
4
- import java .lang .reflect .Method
5
3
6
- import org .junit .runner .Request
7
- import org .junit .runner .notification .RunNotifier
8
4
import org .scalameter .Key .reports ._
9
5
import org .scalameter .PerformanceTest .OnlineRegressionReport
10
6
import org .scalameter .api ._
11
- import org .scalameter .{Context , History , persistence , currentContext }
7
+ import org .scalameter .{Context , History , currentContext , persistence }
12
8
import org .scalameter .reporting .RegressionReporter .Tester
9
+ import test .CompilerTest
13
10
14
- import scala .collection . mutable . ListBuffer
11
+ import scala .io . Source
15
12
16
13
// decorator of persitor to expose info for debugging
17
14
class DecoratorPersistor (p : Persistor ) extends SerializationPersistor {
@@ -39,10 +36,28 @@ class DecoratorPersistor(p: Persistor) extends SerializationPersistor {
39
36
}
40
37
}
41
38
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" ))
46
61
47
62
// NOTE: use `val persistor = ...` would cause persistor ignore command line options for `resultDir`
48
63
override def persistor = new DecoratorPersistor (super .persistor)
@@ -54,24 +69,17 @@ abstract class TestsToBenchmarkConverter
54
69
override def historian : RegressionReporter .Historian = RegressionReporter .Historian .Complete ()
55
70
56
71
override def executor : Executor = LocalExecutor (warmer, aggregator, measurer)
57
- val testNames = getMethodsAnnotatedWith(targetClass, filterAnnot).map(_.getName).sorted
58
-
59
72
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:_*)
64
73
65
74
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
+ }
75
83
}
76
84
77
85
/** workaround to fix problem in ScalaMeter
@@ -89,22 +97,4 @@ abstract class TestsToBenchmarkConverter
89
97
super .executeTests()
90
98
}
91
99
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
- }
108
100
}
109
-
110
- object dotcTests extends TestsToBenchmarkConverter (classOf [dotc.tests])
0 commit comments