diff options
author | aleksandar <aleksandar@lampmac14.epfl.ch> | 2012-01-12 15:28:25 +0100 |
---|---|---|
committer | aleksandar <aleksandar@lampmac14.epfl.ch> | 2012-01-12 15:30:42 +0100 |
commit | 51ddeb372b3f0b22041d9a51f3faee17acd7b749 (patch) | |
tree | 5f1156ed34f7cc429189e18cc88782f13a3bfc86 /test/benchmarking/AVL-insert.scala | |
parent | 178d49df450904330c06cfea9955f120ba04d34c (diff) | |
download | scala-51ddeb372b3f0b22041d9a51f3faee17acd7b749.tar.gz scala-51ddeb372b3f0b22041d9a51f3faee17acd7b749.tar.bz2 scala-51ddeb372b3f0b22041d9a51f3faee17acd7b749.zip |
Add mutable tree sets to the standard library.
This implementation is based on AVL trees.
The current implementation is contributed by Lucien Pereira.
Fixes #4147.
Diffstat (limited to 'test/benchmarking/AVL-insert.scala')
-rw-r--r-- | test/benchmarking/AVL-insert.scala | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/test/benchmarking/AVL-insert.scala b/test/benchmarking/AVL-insert.scala new file mode 100644 index 0000000000..4f3ab390c9 --- /dev/null +++ b/test/benchmarking/AVL-insert.scala @@ -0,0 +1,67 @@ +package scala.collection + + + + + +class Dummy(val a: Int) extends math.Ordered[Dummy] { + def compare(other: Dummy) = this.a - other.a + override def toString = a.toString +} + + +object Global { + val sz = 500000 + val data = (0 until sz) map { new Dummy(_) } toArray +} + + +import Global._ + + +object AVL extends testing.Benchmark { + + def run() { + val avl = new collection.mutable.TreeSet[Dummy] + + var i = 0 + while (i < sz) { + val elem = data(i) + avl += elem + i += 1 + } + } + +} + + +object ImmutableTreeSet extends testing.Benchmark { + + def run() { + var tree = new collection.immutable.TreeSet[Dummy] + + var i = 0 + while (i < sz) { + val elem = data(i) + tree += elem + i += 1 + } + } + +} + + +object JavaTreeSet extends testing.Benchmark { + + def run() { + val tree = new java.util.TreeSet[Dummy] + + var i = 0 + while (i < sz) { + val elem = data(i) + tree add elem + i += 1 + } + } + +} |