@@ -19,7 +19,7 @@ package org.apache.spark.sql.execution.benchmark
1919
2020import java .util .{Arrays , Comparator }
2121
22- import org .apache .spark .benchmark .Benchmark
22+ import org .apache .spark .benchmark .{ Benchmark , BenchmarkBase }
2323import org .apache .spark .unsafe .array .LongArray
2424import org .apache .spark .unsafe .memory .MemoryBlock
2525import 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