From 2616dd6348a87d3d9cd306d3ab76d039c15d10c4 Mon Sep 17 00:00:00 2001 From: Lucien Pereira Date: Sat, 28 Jan 2012 14:43:45 +0100 Subject: Added benchmarking files, in order to easily compare various implementations performances. --- test/benchmarking/TreeSetInsert.scala | 65 +++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 test/benchmarking/TreeSetInsert.scala (limited to 'test/benchmarking/TreeSetInsert.scala') diff --git a/test/benchmarking/TreeSetInsert.scala b/test/benchmarking/TreeSetInsert.scala new file mode 100644 index 0000000000..61b064ae33 --- /dev/null +++ b/test/benchmarking/TreeSetInsert.scala @@ -0,0 +1,65 @@ + +object TreeSetInsert { + + 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]() + + var i = 0 + while (i < length) { + val elem = data(i) + t add 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]() + + 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]() + + var i = 0 + while (i < length) { + val elem = data(i) + t += elem + i += 1 + } + } +} -- cgit v1.2.3