Skip to content

Commit 04db035

Browse files
yucaidongjoon-hyun
authored andcommitted
[SPARK-25486][TEST] Refactor SortBenchmark to use main method
## What changes were proposed in this pull request? Refactor SortBenchmark to use main method. Generate benchmark result: ``` SPARK_GENERATE_BENCHMARK_FILES=1 build/sbt "sql/test:runMain org.apache.spark.sql.execution.benchmark.SortBenchmark" ``` ## How was this patch tested? manual tests Closes #22495 from yucai/SPARK-25486. Authored-by: yucai <[email protected]> Signed-off-by: Dongjoon Hyun <[email protected]>
1 parent 9cbd001 commit 04db035

File tree

2 files changed

+33
-22
lines changed

2 files changed

+33
-22
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
================================================================================================
2+
radix sort
3+
================================================================================================
4+
5+
Java HotSpot(TM) 64-Bit Server VM 1.8.0_162-b12 on Mac OS X 10.13.6
6+
Intel(R) Core(TM) i7-7820HQ CPU @ 2.90GHz
7+
8+
radix sort 25000000: Best/Avg Time(ms) Rate(M/s) Per Row(ns) Relative
9+
------------------------------------------------------------------------------------------------
10+
reference TimSort key prefix array 11770 / 11960 2.1 470.8 1.0X
11+
reference Arrays.sort 2106 / 2128 11.9 84.3 5.6X
12+
radix sort one byte 93 / 100 269.7 3.7 126.9X
13+
radix sort two bytes 171 / 179 146.0 6.9 68.7X
14+
radix sort eight bytes 659 / 664 37.9 26.4 17.9X
15+
radix sort key prefix array 1024 / 1053 24.4 41.0 11.5X
16+
17+

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

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ package org.apache.spark.sql.execution.benchmark
1919

2020
import java.util.{Arrays, Comparator}
2121

22-
import org.apache.spark.benchmark.Benchmark
22+
import org.apache.spark.benchmark.{Benchmark, BenchmarkBase}
2323
import org.apache.spark.unsafe.array.LongArray
2424
import org.apache.spark.unsafe.memory.MemoryBlock
2525
import org.apache.spark.util.collection.Sorter
@@ -28,12 +28,15 @@ import org.apache.spark.util.random.XORShiftRandom
2828

2929
/**
3030
* Benchmark to measure performance for aggregate primitives.
31-
* To run this:
32-
* build/sbt "sql/test-only *benchmark.SortBenchmark"
33-
*
34-
* Benchmarks in this file are skipped in normal builds.
31+
* {{{
32+
* To run this benchmark:
33+
* 1. without sbt: bin/spark-submit --class <this class> <spark sql test jar>
34+
* 2. build/sbt "sql/test:runMain <this class>"
35+
* 3. generate result: SPARK_GENERATE_BENCHMARK_FILES=1 build/sbt "sql/test:runMain <this class>"
36+
* Results will be written to "benchmarks/<this class>-results.txt".
37+
* }}}
3538
*/
36-
class SortBenchmark extends BenchmarkWithCodegen {
39+
object SortBenchmark extends BenchmarkBase {
3740

3841
private def referenceKeyPrefixSort(buf: LongArray, lo: Int, hi: Int, refCmp: PrefixComparator) {
3942
val sortBuffer = new LongArray(MemoryBlock.fromLongArray(new Array[Long](buf.size().toInt)))
@@ -54,10 +57,10 @@ class SortBenchmark extends BenchmarkWithCodegen {
5457
new LongArray(MemoryBlock.fromLongArray(extended)))
5558
}
5659

57-
ignore("sort") {
60+
def sortBenchmark(): Unit = {
5861
val size = 25000000
5962
val rand = new XORShiftRandom(123)
60-
val benchmark = new Benchmark("radix sort " + size, size)
63+
val benchmark = new Benchmark("radix sort " + size, size, output = output)
6164
benchmark.addTimerCase("reference TimSort key prefix array") { timer =>
6265
val array = Array.tabulate[Long](size * 2) { i => rand.nextLong }
6366
val buf = new LongArray(MemoryBlock.fromLongArray(array))
@@ -114,20 +117,11 @@ class SortBenchmark extends BenchmarkWithCodegen {
114117
timer.stopTiming()
115118
}
116119
benchmark.run()
120+
}
117121

118-
/*
119-
Running benchmark: radix sort 25000000
120-
Java HotSpot(TM) 64-Bit Server VM 1.8.0_66-b17 on Linux 3.13.0-44-generic
121-
Intel(R) Core(TM) i7-4600U CPU @ 2.10GHz
122-
123-
radix sort 25000000: Best/Avg Time(ms) Rate(M/s) Per Row(ns) Relative
124-
-------------------------------------------------------------------------------------------
125-
reference TimSort key prefix array 15546 / 15859 1.6 621.9 1.0X
126-
reference Arrays.sort 2416 / 2446 10.3 96.6 6.4X
127-
radix sort one byte 133 / 137 188.4 5.3 117.2X
128-
radix sort two bytes 255 / 258 98.2 10.2 61.1X
129-
radix sort eight bytes 991 / 997 25.2 39.6 15.7X
130-
radix sort key prefix array 1540 / 1563 16.2 61.6 10.1X
131-
*/
122+
override def benchmark(): Unit = {
123+
runBenchmark("radix sort") {
124+
sortBenchmark()
125+
}
132126
}
133127
}

0 commit comments

Comments
 (0)