From eaf6a2201bf29dcb18ea54417c2af89e32d11c4b Mon Sep 17 00:00:00 2001 From: liu fengyun Date: Wed, 9 Nov 2016 15:58:57 +0100 Subject: add mini tests to benchmarks --- bench/test/dotty/tools/benchmarks/Benchmarks.scala | 21 ++++++- bench/tests/exhaustivity-I.scala | 68 ++++++++++++++++++++++ bench/tests/exhaustivity-S.scala | 20 +++++++ bench/tests/exhaustivity-T.scala | 28 +++++++++ bench/tests/exhaustivity-V.scala | 18 ++++++ bench/tests/i1535.scala | 9 +++ bench/tests/i1687.scala | 10 ++++ bench/tests/i490.scala.ignore | 9 +++ bench/tests/implicit-scope-loop.scala | 17 ++++++ bench/tests/implicit_cache.scala | 16 +++++ 10 files changed, 213 insertions(+), 3 deletions(-) create mode 100644 bench/tests/exhaustivity-I.scala create mode 100644 bench/tests/exhaustivity-S.scala create mode 100644 bench/tests/exhaustivity-T.scala create mode 100644 bench/tests/exhaustivity-V.scala create mode 100644 bench/tests/i1535.scala create mode 100644 bench/tests/i1687.scala create mode 100644 bench/tests/i490.scala.ignore create mode 100644 bench/tests/implicit-scope-loop.scala create mode 100644 bench/tests/implicit_cache.scala (limited to 'bench') diff --git a/bench/test/dotty/tools/benchmarks/Benchmarks.scala b/bench/test/dotty/tools/benchmarks/Benchmarks.scala index fe5517ad9..8be592330 100644 --- a/bench/test/dotty/tools/benchmarks/Benchmarks.scala +++ b/bench/test/dotty/tools/benchmarks/Benchmarks.scala @@ -8,6 +8,7 @@ import org.scalameter.reporting.RegressionReporter.Tester import dotty.tools.dotc.CompilerTest import scala.io.Source +import scala.reflect.io.Directory // decorator of persitor to expose info for debugging class DecoratorPersistor(p: Persistor) extends SerializationPersistor { @@ -45,7 +46,8 @@ object BenchTests extends OnlineRegressionReport { implicit val defaultOptions = List("-d", outputDir) val scala2mode = List("-language:Scala2") - val dottyDir = "../compiler/src/dotty/" + val dottyDir = "../compiler/src/dotty/" + val testDir = "./bench/tests/" val stdlibFiles = Source.fromFile("../compiler/test/dotc/scala-collections.whitelist", "UTF8").getLines() .map(_.trim) // allow identation @@ -74,11 +76,24 @@ object BenchTests extends OnlineRegressionReport { def setup = performance of "dotty" in { measure.method("stdlib") in { - using(Gen.unit("test")) curve "stdlib" in { r => stdLib } + // maybe scalac curve later + using(Gen.unit("test")) curve "dotty" in { r => stdLib } } measure.method("dotty-src") in { - using(Gen.unit("test")) curve "dotty-src" in { r => dotty } + using(Gen.unit("test")) curve "dotty" in { r => dotty } + } + + val dir = Directory(testDir) + val fileNames = dir.files.toArray.map(_.jfile.getName).filter(name => (name endsWith ".scala")) + + for (name <- fileNames) { + measure.method(name) in { + // maybe scalac curve later + using(Gen.unit("test")) curve "dotty" in { r => + compiler.compileFile(testDir, name, extension = "") + } + } } } diff --git a/bench/tests/exhaustivity-I.scala b/bench/tests/exhaustivity-I.scala new file mode 100644 index 000000000..cb13893c8 --- /dev/null +++ b/bench/tests/exhaustivity-I.scala @@ -0,0 +1,68 @@ +abstract sealed trait C +case object C1 extends C +case object C2 extends C +case object C3 extends C +case object C4 extends C +case object C5 extends C +case object C6 extends C +case object C7 extends C +case object C8 extends C +case object C9 extends C +case object C10 extends C +case object C11 extends C +case object C12 extends C +case object C13 extends C +case object C14 extends C +case object C15 extends C +case object C16 extends C +case object C17 extends C +case object C18 extends C +case object C19 extends C +case object C20 extends C +case object C21 extends C +case object C22 extends C +case object C23 extends C +case object C24 extends C +case object C25 extends C +case object C26 extends C +case object C27 extends C +case object C28 extends C +case object C29 extends C +case object C30 extends C + +object Test { + + def test(c: C): Int = c match { + case C1 => 1 + case C2 => 2 + case C3 => 3 + case C4 => 4 + case C5 => 5 + case C6 => 6 + case C7 => 7 + case C8 => 8 + case C9 => 9 + case C10 => 10 + case C11 => 11 + case C12 => 12 + case C13 => 13 + case C14 => 14 + case C15 => 15 + case C16 => 16 + case C17 => 17 + case C18 => 18 + case C19 => 19 + case C20 => 20 + case C21 => 21 + case C22 => 22 + case C23 => 23 + case C24 => 24 + case C25 => 25 + case C26 => 26 + case C27 => 27 + case C28 => 28 + case C29 => 29 + case C30 => 30 + + } +} diff --git a/bench/tests/exhaustivity-S.scala b/bench/tests/exhaustivity-S.scala new file mode 100644 index 000000000..ba4fef3fd --- /dev/null +++ b/bench/tests/exhaustivity-S.scala @@ -0,0 +1,20 @@ + +sealed trait O +object A extends O +object B extends O + +object Test { + + def test(x: O) = + (x, x, x, x, x, x, x, x, x, x, x, x, x, x) match { + case (A, A, _, _, _, _, _, _, _, _, _, _, _, _) => 1 + case (_, _, A, A, _, _, _, _, _, _, _, _, _, _) => 2 + case (_, _, _, _, A, A, _, _, _, _, _, _, _, _) => 3 + case (_, _, _, _, _, _, A, A, _, _, _, _, _, _) => 4 + case (_, _, _, _, _, _, _, _, A, A, _, _, _, _) => 5 + case (_, _, _, _, _, _, _, _, _, _, A, A, _, _) => 6 + case (_, _, _, _, _, _, _, _, _, _, _, _, A, A) => 7 + case (B, A, B, A, B, A, B, A, B, A, B, A, B, A) => 8 + + } +} diff --git a/bench/tests/exhaustivity-T.scala b/bench/tests/exhaustivity-T.scala new file mode 100644 index 000000000..4d094758a --- /dev/null +++ b/bench/tests/exhaustivity-T.scala @@ -0,0 +1,28 @@ + +sealed trait O +object A extends O +object B extends O + +object Test { + + def test(x: O) = + (x, x, x, x, x, x, x, x) match { + case (A, A, A, A, A, A, A, A) => 1 + case (B, B, B, B, B, B, B, B) => 2 + case (_, A, A, A, A, A, A, A) => 3 + case (_, B, B, B, B, B, B, B) => 4 + case (_, _, A, A, A, A, A, A) => 5 + case (_, _, B, B, B, B, B, B) => 6 + case (_, _, _, A, A, A, A, A) => 7 + case (_, _, _, B, B, B, B, B) => 8 + case (_, _, _, _, A, A, A, A) => 9 + case (_, _, _, _, B, B, B, B) => 10 + case (_, _, _, _, _, A, A, A) => 11 + case (_, _, _, _, _, B, B, B) => 12 + case (_, _, _, _, _, _, A, A) => 13 + case (_, _, _, _, _, _, B, B) => 14 + case (_, _, _, _, _, _, _, A) => 15 + case (_, _, _, _, _, _, _, B) => 16 + + } +} diff --git a/bench/tests/exhaustivity-V.scala b/bench/tests/exhaustivity-V.scala new file mode 100644 index 000000000..be84934d3 --- /dev/null +++ b/bench/tests/exhaustivity-V.scala @@ -0,0 +1,18 @@ + +sealed trait O +object A extends O +object B extends O + +object Test { + + def test(x: O) = + (x, x, x, x, x, x, x, x, x, x, x, x, x, x, x) match { + case (A, A, A, A, A, _, _, _, _, _, _, _, _, _, _) => 1 + case (B, _, _, _, _, A, A, A, A, _, _, _, _, _, _) => 2 + case (_, B, _, _, _, B, _, _, _, A, A, A, _, _, _) => 3 + case (_, _, B, _, _, _, B, _, _, B, _, _, A, A, _) => 4 + case (_, _, _, B, _, _, _, B, _, _, B, _, B, _, A) => 5 + case (_, _, _, _, B, _, _, _, B, _, _, B, _, B, B) => 6 + + } +} diff --git a/bench/tests/i1535.scala b/bench/tests/i1535.scala new file mode 100644 index 000000000..0433e3ab2 --- /dev/null +++ b/bench/tests/i1535.scala @@ -0,0 +1,9 @@ +object Example { + case class C[H, T](h: H, t: T) + + type I = Int + + val p + : 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]]]]]]]]]]]]]]]]]]]]]]] + = 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))))))))))))))))))))))) +} \ No newline at end of file diff --git a/bench/tests/i1687.scala b/bench/tests/i1687.scala new file mode 100644 index 000000000..7da9d2824 --- /dev/null +++ b/bench/tests/i1687.scala @@ -0,0 +1,10 @@ +object O { + def f: String = { + "1" + 1 + "1" + 1 + + "1" + 1 + "1" + 1 + + "1" + 1 + "1" + 1 + + "1" + 1 + "1" + 1 + + "1" + 1 + "1" + 1 + + "1" + 1 + "1" + 1 + } +} \ No newline at end of file diff --git a/bench/tests/i490.scala.ignore b/bench/tests/i490.scala.ignore new file mode 100644 index 000000000..3758d2917 --- /dev/null +++ b/bench/tests/i490.scala.ignore @@ -0,0 +1,9 @@ +trait Foo { + def app(x: Object)(y: Object): Object +} + +object O { + def main(args: Array[String]): Unit = { + val z: Foo = x => ??? + } +} diff --git a/bench/tests/implicit-scope-loop.scala b/bench/tests/implicit-scope-loop.scala new file mode 100644 index 000000000..162f1a52c --- /dev/null +++ b/bench/tests/implicit-scope-loop.scala @@ -0,0 +1,17 @@ +trait Dummy[T] + + +trait A[T] extends B +trait B extends Dummy[A[Int]] +object B { + implicit def theB: B = new B {} + implicit def theA: A[Int] = new A[Int] {} +} + +object Test { + def getB(implicit b: B) = b + def getA[T](implicit a: A[T]) = a + + getB + getA +} \ No newline at end of file diff --git a/bench/tests/implicit_cache.scala b/bench/tests/implicit_cache.scala new file mode 100644 index 000000000..d124876e0 --- /dev/null +++ b/bench/tests/implicit_cache.scala @@ -0,0 +1,16 @@ +class A +object A { + implicit def theA: A = new A +} +class Foo[T] +object Foo { + implicit def theFoo: Foo[A] = new Foo[A] +} + +object Test { + def getFooA(implicit foo: Foo[A]) = foo + def getA(implicit a: A) = a + + getFooA + getA +} -- cgit v1.2.3