summaryrefslogtreecommitdiff
path: root/test/benchmarks/src/scala/collection/parallel/benchmarks/arrays/IntAccess.scala
blob: 81f0e4da037362b47be105ec34e8377c9420f263 (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
68
package scala.collection.parallel.benchmarks.arrays


import scala.collection.parallel.benchmarks._



object IntAccess extends BenchCompanion {
  def collectionName = "array";
  def benchName = "access-int";
  def apply(sz: Int, p: Int, what: String) = new IntAccess(sz, p, what)
  override def comparisons = List("any", "cast", "manif", "unknown")
  override def defaultSize = 100000
}


class IntAccess(sz: Int, p: Int, what: String)
extends Resetting(n => n, sz, p, what) with UnknownManif[Int] {
  def companion = IntAccess
  
  def runseq {}
  def runpar {}
  
  def runany = {
    var i = 0
    while (i < sz) {
      val d = anyarray(i).asInstanceOf[Int]
      i += 1
    }
  }
  
  def runcast = {
    var i = 0
    while (i < sz) {
      val d = Arrays.apply(castarray, i).asInstanceOf[Int]
      i += 1
    }
  }
  
  def runmanif = {
    var i = 0
    while (i < sz) {
      val d = manifarray(i)
      if (op(d)) i += 1
      i += 1
    }
  }
  
  def op(a: Int) = a < 0
  
  def comparisonMap = collection.Map("any" -> runany _, "cast" -> runcast _,
                                     "manif" -> runmanif _, "unknown" -> rununknown _)
  
}