diff options
Diffstat (limited to 'test/benchmark')
-rw-r--r-- | test/benchmark/ant.private | 9 | ||||
-rw-r--r-- | test/benchmark/build.xml | 23 | ||||
-rw-r--r-- | test/benchmark/predef.xml | 73 | ||||
-rw-r--r-- | test/benchmark/sources/impfor/build.xml | 36 | ||||
-rw-r--r-- | test/benchmark/sources/impfor/impfor.scala | 46 | ||||
-rw-r--r-- | test/benchmark/sources/parsers/build.xml | 37 | ||||
-rw-r--r-- | test/benchmark/sources/parsers/parsers.scala | 124 | ||||
-rw-r--r-- | test/benchmark/sources/sort1/build.xml | 36 | ||||
-rw-r--r-- | test/benchmark/sources/sort1/sort1.scala | 28 | ||||
-rw-r--r-- | test/benchmark/sources/sort2/build.xml | 36 | ||||
-rw-r--r-- | test/benchmark/sources/sort2/sort2.scala | 35 | ||||
-rw-r--r-- | test/benchmark/sources/tak/build.xml | 36 | ||||
-rw-r--r-- | test/benchmark/sources/tak/tak.scala | 29 | ||||
-rw-r--r-- | test/benchmark/sources/viewtest/build.xml | 36 | ||||
-rw-r--r-- | test/benchmark/sources/viewtest/viewtest.scala | 52 |
15 files changed, 0 insertions, 636 deletions
diff --git a/test/benchmark/ant.private b/test/benchmark/ant.private deleted file mode 100644 index a777a19594..0000000000 --- a/test/benchmark/ant.private +++ /dev/null @@ -1,9 +0,0 @@ -# the compiler executable -scala.compiler=scalac - -# the vm to run scala programs with -scala.vm=scala - -# the location where your scala distribution is -# it should point to the parent of the 'test/' directory -scala.home=${user.home}/scala diff --git a/test/benchmark/build.xml b/test/benchmark/build.xml deleted file mode 100644 index 346285163a..0000000000 --- a/test/benchmark/build.xml +++ /dev/null @@ -1,23 +0,0 @@ -<project name="benchmark" default="run.benchmark"> - - <import file="predef.xml"/> - - <target name="init" depends="clean.benchmark"> - <mkdir dir="${benchmark.classes.dir}"/> - <mkdir dir="times"/> - </target> - - <target name="clean.benchmark" - description="Clean the files generated for the benchmark classes"> - <delete dir="${benchmark.classes.dir}"/> - </target> - - <target name="run.benchmark" depends="init" - description="Run the benchmark suite"> - - <subant inheritAll="false"> - <fileset dir="${benchmark.sources.dir}" includes="*/build.xml"/> - </subant> - </target> - -</project> diff --git a/test/benchmark/predef.xml b/test/benchmark/predef.xml deleted file mode 100644 index 3cb362b14d..0000000000 --- a/test/benchmark/predef.xml +++ /dev/null @@ -1,73 +0,0 @@ -<project name="predef"> - - <!-- Include the file defining private properties --> - <dirname property="predef.basedir" file="${ant.file.predef}"/> - <property file="${predef.basedir}/ant.private"/> - - <!-- Define some basic paths --> - <property name="benchmark.home" value="${scala.home}/test/benchmark"/> - <property name="benchmark.sources.dir" - value="${benchmark.home}/sources"/> - <property name="benchmark.classes.dir" - value="${benchmark.home}/classes"/> - <property name="log.file" - value="${benchmark.home}/times/times.log"/> - - <!-- Define a <run-benchmark> element that can be used to run --> - <!-- benchmarks --> - <!-- It accepts these attributes: --> - <!-- count - how many times to run each benchmark (default:5) --> - <!-- classname - the name of the class to be ran (default: --> - <!-- the name of the ant project --> - <!-- logfile - the location of the file where running times --> - <!-- are logged (default: ${log.file} property) --> - <!-- location - the location of the classfiles: it will end --> - <!-- up as head of the current classpath (default: --> - <!-- benchmark classes dir/project name --> - <macrodef name="run-benchmark"> - <attribute name="count" default="5"/> - <attribute name="classname" default="benchmarks.${ant.project.name}"/> - <attribute name="logfile" default="${log.file}"/> - <attribute name="location" default="${benchmark.classes.dir}/${ant.project.name}"/> - - <sequential> - <echo>** Running benchmark @{classname} in @{location}..</echo> - <exec executable="${scala.vm}" failonerror="true"> - <arg line="-cp @{location}:${java.class.path}"/> - <arg line="@{classname} @{count} @{logfile}"/> - </exec> - <echo>Done</echo> - </sequential> - </macrodef> - - <!-- Define a <compile-benchmark> element that can be used to --> - <!-- compile benchmarks --> - <!-- It accepts these attributes: --> - <!-- compiler - the name of the scalac compiler to use. It is --> - <!-- useful in case you have multiple compilers --> - <!-- installed (default: scalac) --> - <!-- additionalArgs - additional arguments to pass to scalac --> - <!-- (default: none) --> - <!-- destination - the location where class files should be --> - <!-- created (default: benchmark classes dir/project --> - <!-- name) --> - <!-- files - the source files to be compiled --> - <macrodef name="compile-benchmark"> - <attribute name="compiler" default="${scala.compiler}"/> - <attribute name="additionalArgs" default=""/> - <attribute name="destination" default="${benchmark.classes.dir}/${ant.project.name}"/> - <attribute name="files"/> - - <sequential> - <echo> -** Building project ${ant.project.name} to @{destination}</echo> - - <exec executable="@{compiler}" failonerror="true"> - <arg line="-d @{destination}"/> - <arg line="@{additionalArgs}"/> - <arg line="@{files}"/> - </exec> - </sequential> - </macrodef> - -</project> diff --git a/test/benchmark/sources/impfor/build.xml b/test/benchmark/sources/impfor/build.xml deleted file mode 100644 index 4feb4599f8..0000000000 --- a/test/benchmark/sources/impfor/build.xml +++ /dev/null @@ -1,36 +0,0 @@ -<project name="impfor" default="run"> - - <import file="../../predef.xml"/> - - <target name="init"> - <mkdir dir="${benchmark.classes.dir}/${ant.project.name}"/> - </target> - - <!-- Compile the impfor benchmark without optimizations --> - <target name="compile-noopt" - description="Compile the ${ant.project.name} benchmark with no optimizations"> - <compile-benchmark files="${benchmark.sources.dir}/${ant.project.name}/impfor.scala" - destination="${benchmark.classes.dir}/${ant.project.name}/noopt"/> - </target> - - <!-- Compile the impfor benchmark with optimizations --> - <target name="compile-opt" - description="Compile the ${ant.project.name} benchmark with opt"> - <compile-benchmark files="${benchmark.sources.dir}/${ant.project.name}/impfor.scala" - destination="${benchmark.classes.dir}/${ant.project.name}/opt" - additionalArgs="-separate:no -Xinline"/> - </target> - - - <target name="run" depends="init,compile-noopt,compile-opt" - description="Run this benchmark"> - <run-benchmark location="${benchmark.classes.dir}/${ant.project.name}/noopt"/> - <run-benchmark location="${benchmark.classes.dir}/${ant.project.name}/opt"/> - </target> - - <target name="clean.benchmark" - description="Clean the object files for ${ant.project.name} benchmark"> - <delete dir="${benchmark.classes.dir}/${ant.project.name}"/> - </target> - -</project> diff --git a/test/benchmark/sources/impfor/impfor.scala b/test/benchmark/sources/impfor/impfor.scala deleted file mode 100644 index f02a4ba31b..0000000000 --- a/test/benchmark/sources/impfor/impfor.scala +++ /dev/null @@ -1,46 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala benchmark suite ** -** / __/ __// _ | / / / _ | (c) 2003-2004, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -** $Id$ -\* */ - - -package benchmarks; - -/** Imperative for construct. Translated from MLton benchmarking suite */ - -class For { - def impFor[A](start: Int, stop: Int, f: Int => A) = { - var i = start; - def loop: Unit = if (i >= stop) () - else { f(i); i = i + 1; loop } - - loop; - } -} - - -object impfor extends For with scala.testing.Benchmark { - - def doit: Unit = { - var x = 0; - - impFor(0, 10, t => - impFor(0, 10, t => - impFor(0, 10, t => - impFor(0, 10, t => - impFor(0, 10, t => - impFor(0, 10, t => - impFor(0, 10, t => x = x + 1))))))); // 7 inner loops - - if (x != 10000000) { - Console.println("Error"); - System.exit(1); - } - } - - def run: Unit = doit; -} diff --git a/test/benchmark/sources/parsers/build.xml b/test/benchmark/sources/parsers/build.xml deleted file mode 100644 index 9217ba443e..0000000000 --- a/test/benchmark/sources/parsers/build.xml +++ /dev/null @@ -1,37 +0,0 @@ -<project name="parsers" default="run"> - - <import file="../../predef.xml"/> - - <target name="init"> - <mkdir dir="${benchmark.classes.dir}/${ant.project.name}"/> - </target> - - - <!-- Compile the parsers benchmark without optimizations --> - <target name="compile-noopt" - description="Compile the ${ant.project.name} benchmark with no optimizations"> - <compile-benchmark files="${benchmark.sources.dir}/${ant.project.name}/parsers.scala" - destination="${benchmark.classes.dir}/${ant.project.name}/noopt"/> - </target> - - <!-- Compile the parsers benchmark with optimizations --> - <target name="compile-opt" - description="Compile the ${ant.project.name} benchmark with opt"> - <compile-benchmark files="${benchmark.sources.dir}/${ant.project.name}/parsers.scala" - destination="${benchmark.classes.dir}/${ant.project.name}/opt" - additionalArgs="-separate:no -Xinline"/> - </target> - - - <target name="run" depends="init,compile-noopt,compile-opt" - description="Run this benchmark"> - <run-benchmark location="${benchmark.classes.dir}/${ant.project.name}/noopt"/> - <run-benchmark location="${benchmark.classes.dir}/${ant.project.name}/opt"/> - </target> - - <target name="clean.benchmark" - description="Clean the object files for ${ant.project.name} benchmark"> - <delete dir="${benchmark.classes.dir}/${ant.project.name}"/> - </target> - -</project> diff --git a/test/benchmark/sources/parsers/parsers.scala b/test/benchmark/sources/parsers/parsers.scala deleted file mode 100644 index 57b79588bc..0000000000 --- a/test/benchmark/sources/parsers/parsers.scala +++ /dev/null @@ -1,124 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala benchmark suite ** -** / __/ __// _ | / / / _ | (c) 2003-2004, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -** $Id$ -\* */ - -package benchmarks; - -/** The parsers example from the scala distribution. */ -abstract class Parsers { - - type intype; - - abstract class Parser { - - type Result = Option[intype]; - - def apply(in: intype): Result; - - /*** p &&& q applies first p, and if that succeeds, then q - */ - def &&& (q: => Parser) = new Parser { - def apply(in: intype): Result = Parser.this.apply(in) match { - case None => None - case Some(in1) => q(in1) - } - } - - /*** p ||| q applies first p, and, if that fails, then q. - */ - def ||| (q: => Parser) = new Parser { - def apply(in: intype): Result = Parser.this.apply(in) match { - case None => q(in) - case s => s - } - } - } - - val empty = new Parser { - def apply(in: intype): Result = Some(in) - } - - val fail = new Parser { - def apply(in: intype): Result = None - } - - def opt(p: Parser): Parser = p ||| empty; // p? = (p | <empty>) - def rep(p: Parser): Parser = opt(rep1(p)); // p* = [p+] - def rep1(p: Parser): Parser = p &&& rep(p); // p+ = p p* -} - -abstract class ListParsers extends Parsers { - - def chr(p: char => boolean): Parser; - - def chr(c: char): Parser = chr(d: char => d == c); - - def letter : Parser = chr(Character.isLetter); - def digit : Parser = chr(Character.isDigit); - - def ident : Parser = letter &&& rep(letter ||| digit); - def number : Parser = digit &&& rep(digit); - def list : Parser = chr('(') &&& listElems &&& chr(')'); - def listElems : Parser = expr &&& (chr(',') &&& listElems ||| empty); - def expr : Parser = ident ||| number ||| list; -} - -abstract class ExprParsers extends Parsers { - def chr(p: char => boolean): Parser; - def chr(c: char): Parser = chr(d: char => d == c); - - def digit : Parser = chr(Character.isDigit); - def number : Parser = digit &&& rep(digit); - def summand : Parser = number ||| chr('(') &&& expr &&& chr(')'); - def expr : Parser = summand &&& rep(chr('+') &&& summand) -} - -class ParseString(s: String) extends Parsers { - type intype = int; - val input = 0; - def chr(p: char => boolean) = new Parser { - def apply(in: int): Parser#Result = - if (in < s.length() && p(s charAt in)) Some(in + 1); - else None; - } -} - -object TestList { - - def main(args: Array[String]): unit = - if (args.length == 1) { - val ps = new ListParsers with ParseString(args(0)); - ps.expr(ps.input) match { - case Some(n) => - System.out.println("parsed: " + args(0).substring(0, n)); - case None => - System.out.println("nothing parsed"); - } - } else System.out.println("usage: java examples.TestList <expr-string>"); -} - -object TestExpr { - - def main(args: Array[String]): unit = - if (args.length == 1) { - val ps = new ExprParsers with ParseString(args(0)); - ps.expr(ps.input) match { - case Some(n) => - System.out.println("parsed: " + args(0).substring(0, n)); - case None => - System.out.println("nothing parsed"); - } - } else System.out.println("usage: java examples.TestExpr <expr-string>"); -} - -object parsers with scala.testing.Benchmark { - def run: Unit = { - TestList.main(Array("(a,b,(1,2))")); - TestExpr.main(Array("2+3+(4+1)")) - } -} diff --git a/test/benchmark/sources/sort1/build.xml b/test/benchmark/sources/sort1/build.xml deleted file mode 100644 index 31f48144cf..0000000000 --- a/test/benchmark/sources/sort1/build.xml +++ /dev/null @@ -1,36 +0,0 @@ -<project name="sort1" default="run"> - - <import file="../../predef.xml"/> - - <target name="init"> - <mkdir dir="${benchmark.classes.dir}/${ant.project.name}"/> - </target> - - <!-- Compile the sort1 benchmark without optimizations --> - <target name="compile-noopt" - description="Compile the ${ant.project.name} benchmark with no optimizations"> - <compile-benchmark files="${benchmark.sources.dir}/${ant.project.name}/sort1.scala" - destination="${benchmark.classes.dir}/${ant.project.name}/noopt"/> - </target> - - <!-- Compile the sort1 benchmark with optimizations --> - <target name="compile-opt" - description="Compile the ${ant.project.name} benchmark with opt"> - <compile-benchmark files="${benchmark.sources.dir}/${ant.project.name}/sort1.scala" - destination="${benchmark.classes.dir}/${ant.project.name}/opt" - additionalArgs="-separate:no -Xinline"/> - </target> - - - <target name="run" depends="init,compile-noopt,compile-opt" - description="Run this benchmark"> - <run-benchmark location="${benchmark.classes.dir}/${ant.project.name}/noopt"/> - <run-benchmark location="${benchmark.classes.dir}/${ant.project.name}/opt"/> - </target> - - <target name="clean.benchmark" - description="Clean the object files for ${ant.project.name} benchmark"> - <delete dir="${benchmark.classes.dir}/${ant.project.name}"/> - </target> - -</project> diff --git a/test/benchmark/sources/sort1/sort1.scala b/test/benchmark/sources/sort1/sort1.scala deleted file mode 100644 index 6795158a78..0000000000 --- a/test/benchmark/sources/sort1/sort1.scala +++ /dev/null @@ -1,28 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala benchmark suite ** -** / __/ __// _ | / / / _ | (c) 2003-2004, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -** $Id$ -\* */ - - -package benchmarks; - -/** Quick sort with a functional taste. */ -object sort1 with scala.testing.Benchmark { - - def sort(a: List[Int]): List[Int] = { - if (a.length < 2) - a - else { - val pivot = a(a.length / 2); - sort(a.filter(x => x < pivot)) - ::: a.filter(x => x == pivot) - ::: sort(a.filter(x => x > pivot)) - } - } - - def run: Unit = sort(List.range(1, 10000)); -} diff --git a/test/benchmark/sources/sort2/build.xml b/test/benchmark/sources/sort2/build.xml deleted file mode 100644 index 067b98afb6..0000000000 --- a/test/benchmark/sources/sort2/build.xml +++ /dev/null @@ -1,36 +0,0 @@ -<project name="sort2" default="run"> - <import file="../../predef.xml"/> - - <target name="init"> - <mkdir dir="${benchmark.classes.dir}/${ant.project.name}"/> - </target> - - - <!-- Compile the sort2 benchmark without optimizations --> - <target name="compile-noopt" - description="Compile the ${ant.project.name} benchmark with no optimizations"> - <compile-benchmark files="${benchmark.sources.dir}/${ant.project.name}/sort2.scala" - destination="${benchmark.classes.dir}/${ant.project.name}/noopt"/> - </target> - - <!-- Compile the sort2 benchmark with optimizations --> - <target name="compile-opt" - description="Compile the ${ant.project.name} benchmark with opt"> - <compile-benchmark files="${benchmark.sources.dir}/${ant.project.name}/sort2.scala" - destination="${benchmark.classes.dir}/${ant.project.name}/opt" - additionalArgs="-separate:no -Xinline"/> - </target> - - - <target name="run" depends="init,compile-noopt,compile-opt" - description="Run this benchmark"> - <run-benchmark location="${benchmark.classes.dir}/${ant.project.name}/noopt"/> - <run-benchmark location="${benchmark.classes.dir}/${ant.project.name}/opt"/> - </target> - - <target name="clean.benchmark" - description="Clean the object files for ${ant.project.name} benchmark"> - <delete dir="${benchmark.classes.dir}/${ant.project.name}"/> - </target> - -</project>
\ No newline at end of file diff --git a/test/benchmark/sources/sort2/sort2.scala b/test/benchmark/sources/sort2/sort2.scala deleted file mode 100644 index 6c024eab7a..0000000000 --- a/test/benchmark/sources/sort2/sort2.scala +++ /dev/null @@ -1,35 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala benchmark suite ** -** / __/ __// _ | / / / _ | (c) 2003-2004, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -** $Id$ -\* */ - -package benchmarks; - -/** Quick-sort a list of integers, version 2. Taken from the - Scala distribution examples. */ -class Sorter { - - def sort(a: List[Int]): List[Int] = { - if (a.length < 2) - a - else { - val pivot = a(a.length / 2); - def lePivot(x: Int) = x < pivot; - def gtPivot(x: Int) = x > pivot; - def eqPivot(x: Int) = x == pivot; - sort(a filter lePivot) - ::: sort(a filter eqPivot) - ::: sort(a filter gtPivot) - } - } - -} - -object sort2 extends Sorter with scala.testing.Benchmark { - def run: Unit = sort(List.range(1,10000)); - -} diff --git a/test/benchmark/sources/tak/build.xml b/test/benchmark/sources/tak/build.xml deleted file mode 100644 index 1fbef5e75d..0000000000 --- a/test/benchmark/sources/tak/build.xml +++ /dev/null @@ -1,36 +0,0 @@ -<project name="tak" default="run"> - - <import file="../../predef.xml"/> - - <target name="init"> - <mkdir dir="${benchmark.classes.dir}/${ant.project.name}"/> - </target> - - <!-- Compile the tak benchmark without optimizations --> - <target name="compile-noopt" - description="Compile the ${ant.project.name} benchmark with no optimizations"> - <compile-benchmark files="${benchmark.sources.dir}/${ant.project.name}/tak.scala" - destination="${benchmark.classes.dir}/${ant.project.name}/noopt"/> - </target> - - <!-- Compile the tak benchmark with optimizations --> - <target name="compile-opt" - description="Compile the ${ant.project.name} benchmark with opt"> - <compile-benchmark files="${benchmark.sources.dir}/${ant.project.name}/tak.scala" - destination="${benchmark.classes.dir}/${ant.project.name}/opt" - additionalArgs="-separate:no -Xinline"/> - </target> - - - <target name="run" depends="init,compile-noopt,compile-opt" - description="Run this benchmark"> - <run-benchmark location="${benchmark.classes.dir}/${ant.project.name}/noopt"/> - <run-benchmark location="${benchmark.classes.dir}/${ant.project.name}/opt"/> - </target> - - <target name="clean.benchmark" - description="Clean the object files for ${ant.project.name} benchmark"> - <delete dir="${benchmark.classes.dir}/${ant.project.name}"/> - </target> - -</project> diff --git a/test/benchmark/sources/tak/tak.scala b/test/benchmark/sources/tak/tak.scala deleted file mode 100644 index 6ee989328f..0000000000 --- a/test/benchmark/sources/tak/tak.scala +++ /dev/null @@ -1,29 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala benchmark suite ** -** / __/ __// _ | / / / _ | (c) 2003-2004, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -** $Id$ -\* */ - -package benchmarks; - -/** The Tak recursive function. Translated from the MLton benchmarking - suite. */ -class Tak { - def tak(x: Int, y: Int, z: Int): Int = - if (! (y < x)) - z - else - tak (tak(x - 1, y, z), tak(y - 1, z, x), tak(z - 1, z, y)); - - def f(x: Int): Unit = x match { - case 0 => (); - case n => {tak (36, 42, 12); f (n - 1) } - } -} - -object tak extends Tak with scala.testing.Benchmark { - def run = f(10000); -} diff --git a/test/benchmark/sources/viewtest/build.xml b/test/benchmark/sources/viewtest/build.xml deleted file mode 100644 index 0816f75a18..0000000000 --- a/test/benchmark/sources/viewtest/build.xml +++ /dev/null @@ -1,36 +0,0 @@ -<project name="viewtest" default="run"> - - <import file="../../predef.xml"/> - - <target name="init"> - <mkdir dir="${benchmark.classes.dir}/${ant.project.name}"/> - </target> - - <!-- Compile the viewtest benchmark without optimizations --> - <target name="compile-noopt" - description="Compile the ${ant.project.name} benchmark with no optimizations"> - <compile-benchmark files="${benchmark.sources.dir}/${ant.project.name}/viewtest.scala" - destination="${benchmark.classes.dir}/${ant.project.name}/noopt"/> - </target> - - <!-- Compile the viewtest benchmark with optimizations --> - <target name="compile-opt" - description="Compile the ${ant.project.name} benchmark with opt"> - <compile-benchmark files="${benchmark.sources.dir}/${ant.project.name}/viewtest.scala" - destination="${benchmark.classes.dir}/${ant.project.name}/opt" - additionalArgs="-separate:no -Xinline"/> - </target> - - - <target name="run" depends="init,compile-noopt,compile-opt" - description="Run this benchmark"> - <run-benchmark location="${benchmark.classes.dir}/${ant.project.name}/noopt"/> - <run-benchmark location="${benchmark.classes.dir}/${ant.project.name}/opt"/> - </target> - - <target name="clean.benchmark" - description="Clean the object files for ${ant.project.name} benchmark"> - <delete dir="${benchmark.classes.dir}/${ant.project.name}"/> - </target> - -</project> diff --git a/test/benchmark/sources/viewtest/viewtest.scala b/test/benchmark/sources/viewtest/viewtest.scala deleted file mode 100644 index 5c7d03f5b4..0000000000 --- a/test/benchmark/sources/viewtest/viewtest.scala +++ /dev/null @@ -1,52 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala benchmark suite ** -** / __/ __// _ | / / / _ | (c) 2003-2004, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -** $Id$ -\* */ - -package benchmarks; - -/* View test class from the scala test suite */ - -trait Ordered[a] { - def < (x: a): boolean; -} - -object O { - def view (x: String): Ordered[String] = new Ordered[String] { - def < (y: String) = x.compareTo(y) < 0; - } -} - -object Empty extends Tree[All]; -case class Node[+c <% Ordered[c]](elem: c, l: Tree[c], r: Tree[c]) extends Tree[c]; - -trait Tree[+a <% Ordered[a]] { - def insert[b >: a <% Ordered[b]](x: b): Tree[b] = this match { - case Empty => new Node(x, Empty, Empty) - case Node(elem, l, r) => - if (x == elem) this - else if (x < elem) Node(elem, l insert x, r) - else Node(elem, l, r insert x); - } - def elements: List[a] = this match { - case Empty => List() - case Node(elem, l, r) => - l.elements ::: List(elem) ::: r.elements - } -} - -object viewtest with scala.testing.Benchmark { - import O.view; - - def run: Unit = { - var t: Tree[String] = Empty; - val args = List("1", "2", "3", "4", "5", "7", "8", "9", "10"); - for (val s <- args) { - t = t insert s - } - } -} |