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




object CountHeavy extends Companion {
  def benchName = "count-heavy";
  def apply(sz: Int, parallelism: Int, what: String) = new CountHeavy(sz, parallelism, what)
  override def comparisons = List("jsr")
  override def defaultSize = 16
  
  val pred = (a: Cont) => heavyCheck(a)
  val predjsr = new extra166y.Ops.Predicate[Cont] {
    def op(a: Cont) = heavyCheck(a)
  }
  
  def heavyCheck(a: Cont) = {
    val n = a.in
    (n until (n + 200)).map(checkPrime(_)).reduceLeft(_ && _)
  }
  def checkPrime(n: Int) = {
    var isPrime = true
    for (i <- 2 until (scala.math.sqrt(n).toInt + 1)) if (n % i == 0) isPrime = false
    isPrime
  }
}

class CountHeavy(sz: Int, p: Int, what: String)
extends Resettable(sz, p, what, new Cont(_), new Array[Any](_), classOf[Cont]) {
  def companion = CountHeavy
  
  def runpar = pa.count(CountHeavy.pred)
  def runseq = sequentialCount(CountHeavy.pred, sz)
  def runjsr = jsrarr.withFilter(CountHeavy.predjsr).size
  def comparisonMap = collection.Map("jsr" -> runjsr _)
}