diff options
Diffstat (limited to 'test/benchmarking/TreeSetInsert.scala')
-rw-r--r-- | test/benchmarking/TreeSetInsert.scala | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/test/benchmarking/TreeSetInsert.scala b/test/benchmarking/TreeSetInsert.scala new file mode 100644 index 0000000000..9ede8aedc5 --- /dev/null +++ b/test/benchmarking/TreeSetInsert.scala @@ -0,0 +1,68 @@ + +object TreeSetInsert { + + 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]() + + var i = 0 + while (i < length) { + val elem = data(i) + t add 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]() + + 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]() + + var i = 0 + while (i < length) { + val elem = data(i) + t += elem + i += 1 + } + } +} |