summaryrefslogtreecommitdiff
path: root/test/benchmarking/TreeSetRemove.scala
diff options
context:
space:
mode:
authorAleksandar Prokopec <axel22@gmail.com>2012-02-16 13:34:06 +0100
committerAleksandar Prokopec <axel22@gmail.com>2012-02-16 13:34:06 +0100
commit53b05bb12f5a7a50448bcac9434389bf95273c45 (patch)
treed10140f4a3f2ea46dd39b47828c1326e9a61681e /test/benchmarking/TreeSetRemove.scala
parentf2ccb43a844e484ae511c8cff3fbf534a0d86ebe (diff)
parent91148376049a152edec12348ff9b7e9e93e6ebe1 (diff)
downloadscala-53b05bb12f5a7a50448bcac9434389bf95273c45.tar.gz
scala-53b05bb12f5a7a50448bcac9434389bf95273c45.tar.bz2
scala-53b05bb12f5a7a50448bcac9434389bf95273c45.zip
Merge branch 'master' into execution-context
Conflicts: src/library/scala/package.scala
Diffstat (limited to 'test/benchmarking/TreeSetRemove.scala')
-rw-r--r--test/benchmarking/TreeSetRemove.scala69
1 files changed, 69 insertions, 0 deletions
diff --git a/test/benchmarking/TreeSetRemove.scala b/test/benchmarking/TreeSetRemove.scala
new file mode 100644
index 0000000000..f84066f336
--- /dev/null
+++ b/test/benchmarking/TreeSetRemove.scala
@@ -0,0 +1,69 @@
+
+object TreeSetRemove {
+
+ def main(args: Array[String]): Unit = {
+ val n = 500000
+ JavaUtilTS.main(args)
+ MutableTS.main(args)
+ ImmutableTS.main(args)
+ }
+}
+
+class Dummy(val a: Int) extends math.Ordered[Dummy] {
+ def compare(other: Dummy) = this.a - other.a
+
+ override def toString = a.toString
+ }
+
+
+object JavaUtilTS extends testing.Benchmark {
+ val length = sys.props("length").toInt
+ 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
+ }
+ }
+}
+
+object MutableTS extends testing.Benchmark {
+ val length = sys.props("length").toInt
+ 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
+ }
+ }
+}
+
+object ImmutableTS extends testing.Benchmark {
+ val length = sys.props("length").toInt
+ 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
+ }
+ }
+}