summaryrefslogtreecommitdiff
path: root/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/ReduceList.scala
blob: f095797d1c96419643b0f4b9a80b17979de4291b (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
package scala.collection.parallel.benchmarks.parallel_array




object ReduceList extends Companion {
  def benchName = "reduce-list";
  def apply(sz: Int, p: Int, what: String) = new ReduceList(sz, p, what)
  override def comparisons = List("jsr")
  override def defaultSize = 20000
}

object ListCreator extends (Int => List[Int]) {
  def apply(idx: Int) = {
    val len = 50 + idx % 100
    (for (i <- 0 until len) yield i).toList
  }
}

object ListOps {
  val redop = (a: List[Int], b: List[Int]) => combineLists(a, b)
  val reducer = new extra166y.Ops.Reducer[List[Int]] {
    def op(a: List[Int], b: List[Int]) = combineLists(a, b)
  }
  def combineLists(a: List[Int], b: List[Int]) = {
    if (a.foldLeft(0)(_ + _) > b.foldLeft(0)(_ + _)) a else b
  }
}

class ReduceList(sz: Int, p: Int, what: String)
extends Resettable[List[Int]](sz, p, what, ListCreator, new Array[Any](_), classOf[List[Int]]) {
  def companion = ReduceList
  override def repetitionsPerRun = 10
  override val runs = 15
  
  def runpar = pa.reduce(ListOps.redop)
  def runseq = sequentialReduce(ListOps.redop, sz, List[Int]())
  def runjsr = jsrarr.reduce(ListOps.reducer, List[Int]())
  override def comparisonMap = collection.Map("jsr" -> runjsr _)
}