summaryrefslogtreecommitdiff
path: root/test/benchmarking/AVL-insert.scala
blob: 4f3ab390c9fac13a3a79506cce848716ff985679 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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
    }
  }
  
}