Skip to content

Commit 8b44b6c

Browse files
authored
Merge pull request #1690 from dotty-staging/bench
Fix benchmarks and add multiple mini benchmark tests
2 parents e9165e4 + 157481b commit 8b44b6c

File tree

11 files changed

+211
-3
lines changed

11 files changed

+211
-3
lines changed

bench/test/dotty/tools/benchmarks/Benchmarks.scala

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import org.scalameter.reporting.RegressionReporter.Tester
88
import dotty.tools.dotc.CompilerTest
99

1010
import scala.io.Source
11+
import scala.reflect.io.Directory
1112

1213
// decorator of persitor to expose info for debugging
1314
class DecoratorPersistor(p: Persistor) extends SerializationPersistor {
@@ -36,7 +37,7 @@ class DecoratorPersistor(p: Persistor) extends SerializationPersistor {
3637
}
3738

3839
object BenchTests extends OnlineRegressionReport {
39-
val outputDir = "./out/"
40+
val outputDir = "../out/"
4041

4142
val compiler = new CompilerTest {
4243
override val defaultOutputDir: String = outputDir
@@ -45,7 +46,8 @@ object BenchTests extends OnlineRegressionReport {
4546
implicit val defaultOptions = List("-d", outputDir)
4647
val scala2mode = List("-language:Scala2")
4748

48-
val dottyDir = "../compiler/src/dotty/"
49+
val dottyDir = "../compiler/src/dotty/"
50+
val testDir = "../bench/tests/"
4951

5052
val stdlibFiles = Source.fromFile("../compiler/test/dotc/scala-collections.whitelist", "UTF8").getLines()
5153
.map(_.trim) // allow identation
@@ -80,6 +82,17 @@ object BenchTests extends OnlineRegressionReport {
8082
measure.method("dotty-src") in {
8183
using(Gen.unit("test")) curve "dotty-src" in { r => dotty }
8284
}
85+
86+
val dir = Directory(testDir)
87+
val fileNames = dir.files.toArray.map(_.jfile.getName).filter(name => (name endsWith ".scala"))
88+
89+
for (name <- fileNames) {
90+
measure.method(name) in {
91+
using(Gen.unit("test")) curve "dotty" in { r =>
92+
compiler.compileFile(testDir, name, extension = "")
93+
}
94+
}
95+
}
8396
}
8497

8598
/** workaround to fix problem in ScalaMeter

bench/tests/exhaustivity-I.scala

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
abstract sealed trait C
2+
case object C1 extends C
3+
case object C2 extends C
4+
case object C3 extends C
5+
case object C4 extends C
6+
case object C5 extends C
7+
case object C6 extends C
8+
case object C7 extends C
9+
case object C8 extends C
10+
case object C9 extends C
11+
case object C10 extends C
12+
case object C11 extends C
13+
case object C12 extends C
14+
case object C13 extends C
15+
case object C14 extends C
16+
case object C15 extends C
17+
case object C16 extends C
18+
case object C17 extends C
19+
case object C18 extends C
20+
case object C19 extends C
21+
case object C20 extends C
22+
case object C21 extends C
23+
case object C22 extends C
24+
case object C23 extends C
25+
case object C24 extends C
26+
case object C25 extends C
27+
case object C26 extends C
28+
case object C27 extends C
29+
case object C28 extends C
30+
case object C29 extends C
31+
case object C30 extends C
32+
33+
object Test {
34+
35+
def test(c: C): Int = c match {
36+
case C1 => 1
37+
case C2 => 2
38+
case C3 => 3
39+
case C4 => 4
40+
case C5 => 5
41+
case C6 => 6
42+
case C7 => 7
43+
case C8 => 8
44+
case C9 => 9
45+
case C10 => 10
46+
case C11 => 11
47+
case C12 => 12
48+
case C13 => 13
49+
case C14 => 14
50+
case C15 => 15
51+
case C16 => 16
52+
case C17 => 17
53+
case C18 => 18
54+
case C19 => 19
55+
case C20 => 20
56+
case C21 => 21
57+
case C22 => 22
58+
case C23 => 23
59+
case C24 => 24
60+
case C25 => 25
61+
case C26 => 26
62+
case C27 => 27
63+
case C28 => 28
64+
case C29 => 29
65+
case C30 => 30
66+
67+
}
68+
}

bench/tests/exhaustivity-S.scala

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
sealed trait O
3+
object A extends O
4+
object B extends O
5+
6+
object Test {
7+
8+
def test(x: O) =
9+
(x, x, x, x, x, x, x, x, x, x, x, x, x, x) match {
10+
case (A, A, _, _, _, _, _, _, _, _, _, _, _, _) => 1
11+
case (_, _, A, A, _, _, _, _, _, _, _, _, _, _) => 2
12+
case (_, _, _, _, A, A, _, _, _, _, _, _, _, _) => 3
13+
case (_, _, _, _, _, _, A, A, _, _, _, _, _, _) => 4
14+
case (_, _, _, _, _, _, _, _, A, A, _, _, _, _) => 5
15+
case (_, _, _, _, _, _, _, _, _, _, A, A, _, _) => 6
16+
case (_, _, _, _, _, _, _, _, _, _, _, _, A, A) => 7
17+
case (B, A, B, A, B, A, B, A, B, A, B, A, B, A) => 8
18+
19+
}
20+
}

bench/tests/exhaustivity-T.scala

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
sealed trait O
3+
object A extends O
4+
object B extends O
5+
6+
object Test {
7+
8+
def test(x: O) =
9+
(x, x, x, x, x, x, x, x) match {
10+
case (A, A, A, A, A, A, A, A) => 1
11+
case (B, B, B, B, B, B, B, B) => 2
12+
case (_, A, A, A, A, A, A, A) => 3
13+
case (_, B, B, B, B, B, B, B) => 4
14+
case (_, _, A, A, A, A, A, A) => 5
15+
case (_, _, B, B, B, B, B, B) => 6
16+
case (_, _, _, A, A, A, A, A) => 7
17+
case (_, _, _, B, B, B, B, B) => 8
18+
case (_, _, _, _, A, A, A, A) => 9
19+
case (_, _, _, _, B, B, B, B) => 10
20+
case (_, _, _, _, _, A, A, A) => 11
21+
case (_, _, _, _, _, B, B, B) => 12
22+
case (_, _, _, _, _, _, A, A) => 13
23+
case (_, _, _, _, _, _, B, B) => 14
24+
case (_, _, _, _, _, _, _, A) => 15
25+
case (_, _, _, _, _, _, _, B) => 16
26+
27+
}
28+
}

bench/tests/exhaustivity-V.scala

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
sealed trait O
3+
object A extends O
4+
object B extends O
5+
6+
object Test {
7+
8+
def test(x: O) =
9+
(x, x, x, x, x, x, x, x, x, x, x, x, x, x, x) match {
10+
case (A, A, A, A, A, _, _, _, _, _, _, _, _, _, _) => 1
11+
case (B, _, _, _, _, A, A, A, A, _, _, _, _, _, _) => 2
12+
case (_, B, _, _, _, B, _, _, _, A, A, A, _, _, _) => 3
13+
case (_, _, B, _, _, _, B, _, _, B, _, _, A, A, _) => 4
14+
case (_, _, _, B, _, _, _, B, _, _, B, _, B, _, A) => 5
15+
case (_, _, _, _, B, _, _, _, B, _, _, B, _, B, B) => 6
16+
17+
}
18+
}

bench/tests/i1535.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
object Example {
2+
case class C[H, T](h: H, t: T)
3+
4+
type I = Int
5+
6+
val p
7+
: C[I,C[I,C[I,C[I,C[I,C[I,C[I,C[I,C[I,C[I,C[I,C[I,C[I,C[I,C[I,C[I,C[I,C[I,C[I,C[I,C[I,C[I,C[I,I]]]]]]]]]]]]]]]]]]]]]]]
8+
= C(1,C(1,C(1,C(1,C(1,C(1,C(1,C(1,C(1,C(1,C(1,C(1,C(1,C(1,C(1,C(1,C(1,C(1,C(1,C(1,C(1,C(1,C(1,1)))))))))))))))))))))))
9+
}

bench/tests/i1687.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
object O {
2+
def f: String = {
3+
"1" + 1 + "1" + 1 +
4+
"1" + 1 + "1" + 1 +
5+
"1" + 1 + "1" + 1 +
6+
"1" + 1 + "1" + 1 +
7+
"1" + 1 + "1" + 1 +
8+
"1" + 1 + "1" + 1
9+
}
10+
}

bench/tests/i490.scala.ignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
trait Foo {
2+
def app(x: Object)(y: Object): Object
3+
}
4+
5+
object O {
6+
def main(args: Array[String]): Unit = {
7+
val z: Foo = x => ???
8+
}
9+
}

bench/tests/implicit-scope-loop.scala

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
trait Dummy[T]
2+
3+
4+
trait A[T] extends B
5+
trait B extends Dummy[A[Int]]
6+
object B {
7+
implicit def theB: B = new B {}
8+
implicit def theA: A[Int] = new A[Int] {}
9+
}
10+
11+
object Test {
12+
def getB(implicit b: B) = b
13+
def getA[T](implicit a: A[T]) = a
14+
15+
getB
16+
getA
17+
}

bench/tests/implicit_cache.scala

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class A
2+
object A {
3+
implicit def theA: A = new A
4+
}
5+
class Foo[T]
6+
object Foo {
7+
implicit def theFoo: Foo[A] = new Foo[A]
8+
}
9+
10+
object Test {
11+
def getFooA(implicit foo: Foo[A]) = foo
12+
def getA(implicit a: A) = a
13+
14+
getFooA
15+
getA
16+
}

compiler/test/dotc/tests.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ class tests extends CompilerTest {
107107
Directory(defaultOutputDir + "java").deleteRecursively()
108108
}
109109

110-
@Test def pickle_pickleOK = compileDir(testsDir, "pickling", testPickling)
110+
@Test def pickle_pickleOK = compileFiles(testsDir + "pickling/", testPickling)
111111
// This directory doesn't exist anymore
112112
// @Test def pickle_pickling = compileDir(coreDir, "pickling", testPickling)
113113
@Test def pickle_ast = compileDir(dotcDir, "ast", testPickling)

0 commit comments

Comments
 (0)