@@ -19,20 +19,21 @@ package org.apache.spark.sql.execution.benchmark
19
19
20
20
import scala .util .Random
21
21
22
- import org .apache .spark .benchmark .Benchmark
22
+ import org .apache .spark .benchmark .{ Benchmark , BenchmarkBase }
23
23
import org .apache .spark .sql .catalyst .encoders .ExpressionEncoder
24
- import org .apache .spark .sql .catalyst .expressions .{UnsafeArrayData , UnsafeRow }
25
- import org .apache .spark .sql .catalyst .expressions .codegen .{BufferHolder , UnsafeArrayWriter }
24
+ import org .apache .spark .sql .catalyst .expressions .UnsafeArrayData
26
25
27
26
/**
28
27
* Benchmark [[UnsafeArrayDataBenchmark ]] for UnsafeArrayData
29
- * To run this:
30
- * 1. replace ignore(...) with test(...)
31
- * 2. build/sbt "sql/test-only *benchmark.UnsafeArrayDataBenchmark"
32
- *
33
- * Benchmarks in this file are skipped in normal builds.
28
+ * To run this benchmark:
29
+ * {{{
30
+ * 1. without sbt: bin/spark-submit --class <this class> <spark sql test jar>
31
+ * 2. build/sbt "sql/test:runMain <this class>"
32
+ * 3. generate result: SPARK_GENERATE_BENCHMARK_FILES=1 build/sbt "sql/test:runMain <this class>"
33
+ * Results will be written to "benchmarks/UnsafeArrayDataBenchmark-results.txt".
34
+ * }}}
34
35
*/
35
- class UnsafeArrayDataBenchmark extends BenchmarkWithCodegen {
36
+ object UnsafeArrayDataBenchmark extends BenchmarkBase {
36
37
37
38
def calculateHeaderPortionInBytes (count : Int ) : Int = {
38
39
/* 4 + 4 * count // Use this expression for SPARK-15962 */
@@ -77,18 +78,10 @@ class UnsafeArrayDataBenchmark extends BenchmarkWithCodegen {
77
78
}
78
79
}
79
80
80
- val benchmark = new Benchmark (" Read UnsafeArrayData" , count * iters)
81
+ val benchmark = new Benchmark (" Read UnsafeArrayData" , count * iters, output = output )
81
82
benchmark.addCase(" Int" )(readIntArray)
82
83
benchmark.addCase(" Double" )(readDoubleArray)
83
84
benchmark.run
84
- /*
85
- OpenJDK 64-Bit Server VM 1.8.0_91-b14 on Linux 4.4.11-200.fc22.x86_64
86
- Intel Xeon E3-12xx v2 (Ivy Bridge)
87
- Read UnsafeArrayData: Best/Avg Time(ms) Rate(M/s) Per Row(ns) Relative
88
- ------------------------------------------------------------------------------------------------
89
- Int 252 / 260 666.1 1.5 1.0X
90
- Double 281 / 292 597.7 1.7 0.9X
91
- */
92
85
}
93
86
94
87
def writeUnsafeArray (iters : Int ): Unit = {
@@ -121,18 +114,10 @@ class UnsafeArrayDataBenchmark extends BenchmarkWithCodegen {
121
114
doubleTotalLength = len
122
115
}
123
116
124
- val benchmark = new Benchmark (" Write UnsafeArrayData" , count * iters)
117
+ val benchmark = new Benchmark (" Write UnsafeArrayData" , count * iters, output = output )
125
118
benchmark.addCase(" Int" )(writeIntArray)
126
119
benchmark.addCase(" Double" )(writeDoubleArray)
127
120
benchmark.run
128
- /*
129
- OpenJDK 64-Bit Server VM 1.8.0_91-b14 on Linux 4.4.11-200.fc22.x86_64
130
- Intel Xeon E3-12xx v2 (Ivy Bridge)
131
- Write UnsafeArrayData: Best/Avg Time(ms) Rate(M/s) Per Row(ns) Relative
132
- ------------------------------------------------------------------------------------------------
133
- Int 196 / 249 107.0 9.3 1.0X
134
- Double 227 / 367 92.3 10.8 0.9X
135
- */
136
121
}
137
122
138
123
def getPrimitiveArray (iters : Int ): Unit = {
@@ -167,18 +152,11 @@ class UnsafeArrayDataBenchmark extends BenchmarkWithCodegen {
167
152
doubleTotalLength = len
168
153
}
169
154
170
- val benchmark = new Benchmark (" Get primitive array from UnsafeArrayData" , count * iters)
155
+ val benchmark =
156
+ new Benchmark (" Get primitive array from UnsafeArrayData" , count * iters, output = output)
171
157
benchmark.addCase(" Int" )(readIntArray)
172
158
benchmark.addCase(" Double" )(readDoubleArray)
173
159
benchmark.run
174
- /*
175
- OpenJDK 64-Bit Server VM 1.8.0_91-b14 on Linux 4.4.11-200.fc22.x86_64
176
- Intel Xeon E3-12xx v2 (Ivy Bridge)
177
- Get primitive array from UnsafeArrayData: Best/Avg Time(ms) Rate(M/s) Per Row(ns) Relative
178
- ------------------------------------------------------------------------------------------------
179
- Int 151 / 198 415.8 2.4 1.0X
180
- Double 214 / 394 293.6 3.4 0.7X
181
- */
182
160
}
183
161
184
162
def putPrimitiveArray (iters : Int ): Unit = {
@@ -209,24 +187,19 @@ class UnsafeArrayDataBenchmark extends BenchmarkWithCodegen {
209
187
doubleTotalLen = len
210
188
}
211
189
212
- val benchmark = new Benchmark (" Create UnsafeArrayData from primitive array" , count * iters)
190
+ val benchmark =
191
+ new Benchmark (" Create UnsafeArrayData from primitive array" , count * iters, output = output)
213
192
benchmark.addCase(" Int" )(createIntArray)
214
193
benchmark.addCase(" Double" )(createDoubleArray)
215
194
benchmark.run
216
- /*
217
- OpenJDK 64-Bit Server VM 1.8.0_91-b14 on Linux 4.4.11-200.fc22.x86_64
218
- Intel Xeon E3-12xx v2 (Ivy Bridge)
219
- Create UnsafeArrayData from primitive array: Best/Avg Time(ms) Rate(M/s) Per Row(ns) Relative
220
- ------------------------------------------------------------------------------------------------
221
- Int 206 / 211 306.0 3.3 1.0X
222
- Double 232 / 406 271.6 3.7 0.9X
223
- */
224
195
}
225
196
226
- ignore(" Benchmark UnsafeArrayData" ) {
227
- readUnsafeArray(10 )
228
- writeUnsafeArray(10 )
229
- getPrimitiveArray(5 )
230
- putPrimitiveArray(5 )
197
+ override def runBenchmarkSuite (): Unit = {
198
+ runBenchmark(" Benchmark UnsafeArrayData" ) {
199
+ readUnsafeArray(10 )
200
+ writeUnsafeArray(10 )
201
+ getPrimitiveArray(5 )
202
+ putPrimitiveArray(5 )
203
+ }
231
204
}
232
205
}
0 commit comments