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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
|
package scala.collection.parallel
import scala.collection.mutable.LinkedHashSet
import benchmarks._
/**
* All benchmarks are registered here.
*
* @author prokopec
*/
trait BenchmarkRegister {
val benchcreators = LinkedHashSet[BenchCompanion]()
def register(companion: BenchCompanion) = benchcreators += companion
// parallel array benchmarks
register(parallel_array.ReduceLight)
register(parallel_array.ReduceNew)
register(parallel_array.ReduceList)
register(parallel_array.ReducePrime)
register(parallel_array.ReduceHeavy)
register(parallel_array.CountLight)
register(parallel_array.CountList)
register(parallel_array.CountHeavy)
register(parallel_array.ForeachLight)
register(parallel_array.ForeachHeavy)
register(parallel_array.SumLight)
register(parallel_array.MinLight)
register(parallel_array.MapLight)
register(parallel_array.FilterLight)
register(parallel_array.PartitionLight)
register(parallel_array.PartialMapLight)
register(parallel_array.FlatMapLight)
register(parallel_array.PlusPlus)
register(parallel_array.ForallLight)
register(parallel_array.ForallQuickStop)
register(parallel_array.ForallStop80k)
register(parallel_array.ForallHeavy)
register(parallel_array.ExistsLight)
register(parallel_array.FindLight)
register(parallel_array.TakeMany)
register(parallel_array.DropMany)
register(parallel_array.SliceMany)
register(parallel_array.SliceMedium)
register(parallel_array.SliceFew)
register(parallel_array.SplitHalf)
register(parallel_array.TakeWhileLight)
register(parallel_array.SpanLight)
register(parallel_array.CopyToArray)
register(parallel_array.SegmentLength)
register(parallel_array.IndexWhere)
register(parallel_array.LastIndexWhere)
register(parallel_array.Reverse)
register(parallel_array.ReverseMap)
register(parallel_array.SameElementsLong)
register(parallel_array.Corresponds)
register(parallel_array.DiffHalf)
register(parallel_array.IntersectHalf)
register(parallel_array.RemoveDuplicates)
register(parallel_array.PatchHalf)
register(parallel_array.PadToDouble)
register(parallel_array.AggregateLight)
register(parallel_array.ScanLight)
register(parallel_array.MatrixMultiplication)
// parallel views
register(parallel_view.DummyViewBenchList.Reduce)
register(parallel_view.DummyViewBenchList.MediumReduce)
register(parallel_view.DummyViewBenchList.ModifyThenReduce)
register(parallel_view.DummyViewBenchList.ModifyThenForce)
register(parallel_view.DummyViewBenchList.Iteration)
register(parallel_view.DummyViewBenchList.IterationS)
register(parallel_view.DummyViewBenchList.IterationM)
register(parallel_view.DummyViewBenchList.IterationA)
// parallel ranges
register(parallel_range.RangeBenches.Reduce)
register(parallel_range.RangeBenches.ReduceMedium)
register(parallel_range.RangeBenches.ForeachAdd)
register(parallel_range.RangeBenches.ForeachAddCollatz)
register(parallel_range.RangeBenches.ForeachModify)
register(parallel_range.RangeBenches.ForeachModifyMedium)
register(parallel_range.RangeBenches.ForeachModifyHeavy)
register(parallel_range.RangeBenches.MapLight)
register(parallel_range.RangeBenches.MapMedium)
// array benchmarks
register(arrays.ObjectAccess)
register(arrays.IntAccess)
// hash benchmarks
register(hashtries.Foreach)
register(hashtries.Iterate)
register(hashtries.Construct)
register(hashtries.Lookup)
register(hashtries.Combine)
register(hashtries.MultipleCombine)
// parallel hash trie benchmarks
register(hashtries.RefParHashTrieBenches.Reduce)
register(hashtries.RefParHashTrieBenches.ReduceMedium)
register(hashtries.RefParHashTrieBenches.Reduce2)
register(hashtries.RefParHashTrieBenches.Map)
register(hashtries.RefParHashTrieBenches.Map2)
}
/**
* Serves as an entrypoint to run all the benchmarks.
*/
object Benchmarking extends BenchmarkRegister {
def printHelp {
println("Must enter at least four arguments: <collection> <benchmark> <size of the collection> <type>")
println(" Example: ParArray reduce-light 50000 par")
println(" Example: ParArray -all 50000 par")
println
println("General synthax: <collection> <benchmark> <size> <type> <parallelism-level>")
println(" <collection> - name of the collection to test, `-all` runs benchmarks for all collections")
println(" <benchmark> - name of the specific benchmark, `-all` runs all benchmarks for the chosen collections")
println(" <size> - the size (number of elements) of the collection, or `-default` for default size per benchmark")
println(" <type> - `seq` for benchmarking sequential version of the functionality")
println(" `par` for benchmarking parallel version of the functionality")
println(" `<something-else>` for running comparison benchmarks")
println(" `-all` for running sequential, parallel and comparison benchmarks")
println(" <parallelism-level> - the level of parallelism used (default 2)")
}
def otherOptions(args: Array[String]) {
if (args.length == 0) printHelp
else args(0) match {
case "-list" => // lists all benchmarks
for (bc <- benchcreators) println(bc.fullname)
case _ => printHelp
}
}
def main(args: Array[String]) {
if (args.length < 4) {
otherOptions(args)
return
}
val collname = args(0)
val benchname = args(1)
val size = if (args(2) == "-default") -1 else args(2).toInt
val tpe = args(3)
val parlevel = if (args.length >= 5) args(4).toInt else 2
// find all benchmarks to run
val benches = benchcreators.filter(comp => {
(collname, benchname) match {
case ("-all", "-all") => true
case ("-all", bn) if (benchname != "-all") => bn == comp.benchName
case (cn, "-all") if (collname != "-all") => cn == comp.collectionName
case (cn, bn) => cn == comp.collectionName && bn == comp.benchName
}
}).flatMap(comp => {
val collsz = if (size != -1) size else comp.defaultSize
if (tpe != "-all") List(comp.apply(collsz, parlevel, tpe))
else for (benchtype <- "seq" :: "par" :: comp.comparisons)
yield comp.apply(collsz, parlevel, benchtype)
})
println("Running benchmarks...")
for (b <- benches) b.executeBenchmark
}
}
|