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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
package scala.collection.parallel.benchmarks.hashtables
import scala.collection.parallel.benchmarks.generic.StandardParIterableBenches
import scala.collection.parallel.benchmarks.generic.Dummy
import scala.collection.parallel.benchmarks.generic.DummyOperators
import scala.collection.parallel.mutable.ParHashSet
trait ParHashTableSetBenches[T] extends StandardParIterableBenches[T, ParHashSet[T]] {
def nameOfCollection = "mutable.ParHashSet"
def comparisonMap = collection.mutable.Set()
val forkJoinPool = new scala.concurrent.forkjoin.ForkJoinPool
object Map2 extends IterableBenchCompanion {
override def defaultSize = 50000
override def comparisons = List()
def benchName = "map2";
def apply(sz: Int, p: Int, w: String) = new Map2(sz, p, w)
}
class Map2(val size: Int, val parallelism: Int, val runWhat: String)
extends IterableBench {
var result: Int = 0
def comparisonMap = collection.Map()
def runseq = {
val r = this.seqcoll.asInstanceOf[collection.mutable.HashSet[T]].map(operators.mapper2)
result = r.size
}
def runpar = {
result = this.parcoll.map(operators.mapper2).size
}
def companion = Map2
override def repetitionsPerRun = 50
override def printResults {
println("Size of last result: " + result)
}
}
object HeavyMap extends IterableBenchCompanion {
override def defaultSize = 5000
override def comparisons = List()
def benchName = "heavy-map";
def apply(sz: Int, p: Int, w: String) = new HeavyMap(sz, p, w)
}
class HeavyMap(val size: Int, val parallelism: Int, val runWhat: String)
extends IterableBench {
var result: Int = 0
def comparisonMap = collection.Map()
def runseq = {
val r = this.seqcoll.asInstanceOf[collection.mutable.HashSet[T]].map(operators.heavymapper)
result = r.size
}
def runpar = {
result = this.parcoll.map(operators.heavymapper).size
}
def companion = HeavyMap
override def repetitionsPerRun = 50
}
object Reduce2 extends IterableBenchCompanion {
override def defaultSize = 50000
override def comparisons = List()
def benchName = "reduce2";
def apply(sz: Int, p: Int, w: String) = new Reduce2(sz, p, w)
}
class Reduce2(val size: Int, val parallelism: Int, val runWhat: String)
extends IterableBench {
def comparisonMap = collection.Map()
def runseq = this.seqcoll.reduceLeft(operators.mediumreducer)
def runpar = this.parcoll.reduce(operators.mediumreducer)
def companion = Reduce2
}
object Foreach extends IterableBenchCompanion {
override def defaultSize = 50000
override def comparisons = List()
def benchName = "foreach";
def apply(sz: Int, p: Int, w: String) = new Foreach(sz, p, w)
}
class Foreach(val size: Int, val parallelism: Int, val runWhat: String)
extends IterableBench {
def comparisonMap = collection.Map()
def runseq = this.seqcoll.foreach(operators.foreachFun)
def runpar = this.parcoll.foreach(operators.foreachFun)
def companion = Foreach
}
}
object RefParHashTableSetBenches extends ParHashTableSetBenches[Dummy] {
object ForeachSet extends IterableBenchCompanion {
override def defaultSize = 50000
override def comparisons = List()
def benchName = "foreach-set";
def apply(sz: Int, p: Int, w: String) = new ForeachSet(sz, p, w)
}
class ForeachSet(val size: Int, val parallelism: Int, val runWhat: String)
extends IterableBench {
val array = new Array[Int](size)
def comparisonMap = collection.Map()
def runseq = for (x <- this.seqcoll) array(x.in) += 1
def runpar = for (x <- this.parcoll) array(x.in) += 1
def companion = ForeachSet
override def onEnd {
for (i <- 0 until array.length) {
assert(array(i) == repetitionsPerRun * runs)
}
}
}
val operators = DummyOperators
def createSequential(sz: Int, p: Int) = {
val ht = new collection.mutable.HashSet[Dummy]
for (i <- 0 until sz) ht += new Dummy(i)
ht
}
def createParallel(sz: Int, p: Int) = {
val phm = new ParHashSet[Dummy]
for (i <- 0 until sz) phm += new Dummy(i)
forkJoinPool.setParallelism(p)
phm.tasksupport.environment = forkJoinPool
phm
}
}
|