summaryrefslogtreecommitdiff
path: root/test/benchmarking/TreeSetRemove.scala
diff options
context:
space:
mode:
authorAleksandar Prokopec <aleksandar.prokopec@gmail.com>2012-01-30 02:17:08 -0800
committerAleksandar Prokopec <aleksandar.prokopec@gmail.com>2012-01-30 02:17:08 -0800
commitbdb3fc80514c6c105e3a5edcb6a040ba2f6be3e3 (patch)
tree01f1d71b1858c435b23f49cd4aabba6e1df06949 /test/benchmarking/TreeSetRemove.scala
parent5e9dd4a05c25f463f29d0fbc2f1bec194bf7700b (diff)
parent06945b6dcfc7bbb0efb5f8429ffeab7fbde9be5b (diff)
downloadscala-bdb3fc80514c6c105e3a5edcb6a040ba2f6be3e3.tar.gz
scala-bdb3fc80514c6c105e3a5edcb6a040ba2f6be3e3.tar.bz2
scala-bdb3fc80514c6c105e3a5edcb6a040ba2f6be3e3.zip
Merge pull request #1 from lpereir4/avl
AvlTree performance improvements
Diffstat (limited to 'test/benchmarking/TreeSetRemove.scala')
-rw-r--r--test/benchmarking/TreeSetRemove.scala66
1 files changed, 66 insertions, 0 deletions
diff --git a/test/benchmarking/TreeSetRemove.scala b/test/benchmarking/TreeSetRemove.scala
new file mode 100644
index 0000000000..68c07ce70a
--- /dev/null
+++ b/test/benchmarking/TreeSetRemove.scala
@@ -0,0 +1,66 @@
+
+object TreeSetRemove {
+
+ def main(args: Array[String]): Unit = {
+ val n = 500000
+ new JavaUtilTS(n).main(args)
+ new MutableTS(n).main(args)
+ new ImmutableTS(n).main(args)
+ }
+}
+
+class Dummy(val a: Int) extends math.Ordered[Dummy] {
+ def compare(other: Dummy) = this.a - other.a
+
+ override def toString = a.toString
+ }
+
+
+class JavaUtilTS(val length: Int) extends testing.Benchmark {
+ var data: Array[Dummy] = (0 until length) map { a => new Dummy(a) } toArray
+ var t: java.util.TreeSet[Dummy] = null
+
+ def run = {
+ t = new java.util.TreeSet[Dummy]()
+ data foreach { a => t add a }
+
+ var i = 0
+ while (i < length) {
+ val elem = data(i)
+ t remove elem
+ i += 1
+ }
+ }
+}
+
+class MutableTS(val length: Int) extends testing.Benchmark {
+ var data: Array[Dummy] = (0 until length) map { a => new Dummy(a) } toArray
+ var t: collection.mutable.TreeSet[Dummy] = null
+
+ def run = {
+ t = collection.mutable.TreeSet[Dummy](data: _*)
+
+ var i = 0
+ while (i < length) {
+ val elem = data(i)
+ t -= elem
+ i += 1
+ }
+ }
+}
+
+class ImmutableTS(val length: Int) extends testing.Benchmark {
+ var data: Array[Dummy] = (0 until length) map { a => new Dummy(a) } toArray
+ var t: collection.immutable.TreeSet[Dummy] = null
+
+ def run = {
+ t = collection.immutable.TreeSet[Dummy](data: _*)
+
+ var i = 0
+ while (i < length) {
+ val elem = data(i)
+ t -= elem
+ i += 1
+ }
+ }
+}