Skip to content

Commit 56741c3

Browse files
[SPARK-25483][TEST] Refactor UnsafeArrayDataBenchmark to use main method
## What changes were proposed in this pull request? Refactor `UnsafeArrayDataBenchmark` to use main method. Generate benchmark result: ```sh SPARK_GENERATE_BENCHMARK_FILES=1 build/sbt "sql/test:runMain org.apache.spark.sql.execution.benchmark.UnsafeArrayDataBenchmark" ``` ## How was this patch tested? manual tests Closes apache#22491 from wangyum/SPARK-25483. Lead-authored-by: Yuming Wang <[email protected]> Co-authored-by: Dongjoon Hyun <[email protected]> Signed-off-by: Dongjoon Hyun <[email protected]>
1 parent 1a5d83b commit 56741c3

File tree

2 files changed

+56
-50
lines changed

2 files changed

+56
-50
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
================================================================================================
2+
Benchmark UnsafeArrayData
3+
================================================================================================
4+
5+
OpenJDK 64-Bit Server VM 1.8.0_181-b13 on Linux 3.10.0-862.3.2.el7.x86_64
6+
Intel(R) Xeon(R) CPU E5-2670 v2 @ 2.50GHz
7+
Read UnsafeArrayData: Best/Avg Time(ms) Rate(M/s) Per Row(ns) Relative
8+
------------------------------------------------------------------------------------------------
9+
Int 233 / 234 718.6 1.4 1.0X
10+
Double 244 / 244 687.0 1.5 1.0X
11+
12+
OpenJDK 64-Bit Server VM 1.8.0_181-b13 on Linux 3.10.0-862.3.2.el7.x86_64
13+
Intel(R) Xeon(R) CPU E5-2670 v2 @ 2.50GHz
14+
Write UnsafeArrayData: Best/Avg Time(ms) Rate(M/s) Per Row(ns) Relative
15+
------------------------------------------------------------------------------------------------
16+
Int 32 / 33 658.6 1.5 1.0X
17+
Double 73 / 75 287.0 3.5 0.4X
18+
19+
OpenJDK 64-Bit Server VM 1.8.0_181-b13 on Linux 3.10.0-862.3.2.el7.x86_64
20+
Intel(R) Xeon(R) CPU E5-2670 v2 @ 2.50GHz
21+
Get primitive array from UnsafeArrayData: Best/Avg Time(ms) Rate(M/s) Per Row(ns) Relative
22+
------------------------------------------------------------------------------------------------
23+
Int 70 / 72 895.0 1.1 1.0X
24+
Double 141 / 143 446.9 2.2 0.5X
25+
26+
OpenJDK 64-Bit Server VM 1.8.0_181-b13 on Linux 3.10.0-862.3.2.el7.x86_64
27+
Intel(R) Xeon(R) CPU E5-2670 v2 @ 2.50GHz
28+
Create UnsafeArrayData from primitive array: Best/Avg Time(ms) Rate(M/s) Per Row(ns) Relative
29+
------------------------------------------------------------------------------------------------
30+
Int 72 / 73 874.7 1.1 1.0X
31+
Double 145 / 146 433.7 2.3 0.5X
32+
33+

sql/core/src/test/scala/org/apache/spark/sql/execution/benchmark/UnsafeArrayDataBenchmark.scala

Lines changed: 23 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,21 @@ package org.apache.spark.sql.execution.benchmark
1919

2020
import scala.util.Random
2121

22-
import org.apache.spark.benchmark.Benchmark
22+
import org.apache.spark.benchmark.{Benchmark, BenchmarkBase}
2323
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
2625

2726
/**
2827
* 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+
* }}}
3435
*/
35-
class UnsafeArrayDataBenchmark extends BenchmarkWithCodegen {
36+
object UnsafeArrayDataBenchmark extends BenchmarkBase {
3637

3738
def calculateHeaderPortionInBytes(count: Int) : Int = {
3839
/* 4 + 4 * count // Use this expression for SPARK-15962 */
@@ -77,18 +78,10 @@ class UnsafeArrayDataBenchmark extends BenchmarkWithCodegen {
7778
}
7879
}
7980

80-
val benchmark = new Benchmark("Read UnsafeArrayData", count * iters)
81+
val benchmark = new Benchmark("Read UnsafeArrayData", count * iters, output = output)
8182
benchmark.addCase("Int")(readIntArray)
8283
benchmark.addCase("Double")(readDoubleArray)
8384
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-
*/
9285
}
9386

9487
def writeUnsafeArray(iters: Int): Unit = {
@@ -121,18 +114,10 @@ class UnsafeArrayDataBenchmark extends BenchmarkWithCodegen {
121114
doubleTotalLength = len
122115
}
123116

124-
val benchmark = new Benchmark("Write UnsafeArrayData", count * iters)
117+
val benchmark = new Benchmark("Write UnsafeArrayData", count * iters, output = output)
125118
benchmark.addCase("Int")(writeIntArray)
126119
benchmark.addCase("Double")(writeDoubleArray)
127120
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-
*/
136121
}
137122

138123
def getPrimitiveArray(iters: Int): Unit = {
@@ -167,18 +152,11 @@ class UnsafeArrayDataBenchmark extends BenchmarkWithCodegen {
167152
doubleTotalLength = len
168153
}
169154

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)
171157
benchmark.addCase("Int")(readIntArray)
172158
benchmark.addCase("Double")(readDoubleArray)
173159
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-
*/
182160
}
183161

184162
def putPrimitiveArray(iters: Int): Unit = {
@@ -209,24 +187,19 @@ class UnsafeArrayDataBenchmark extends BenchmarkWithCodegen {
209187
doubleTotalLen = len
210188
}
211189

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)
213192
benchmark.addCase("Int")(createIntArray)
214193
benchmark.addCase("Double")(createDoubleArray)
215194
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-
*/
224195
}
225196

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+
}
231204
}
232205
}

0 commit comments

Comments
 (0)