Repository: spark Updated Branches: refs/heads/master 1a5d83bed -> 56741c342
[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 #22491 from wangyum/SPARK-25483. Lead-authored-by: Yuming Wang <yumw...@ebay.com> Co-authored-by: Dongjoon Hyun <dongj...@apache.org> Signed-off-by: Dongjoon Hyun <dongj...@apache.org> Project: http://git-wip-us.apache.org/repos/asf/spark/repo Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/56741c34 Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/56741c34 Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/56741c34 Branch: refs/heads/master Commit: 56741c342dce87a75b39e52db6de92d7d7bef371 Parents: 1a5d83b Author: Yuming Wang <yumw...@ebay.com> Authored: Wed Oct 3 04:20:02 2018 -0700 Committer: Dongjoon Hyun <dongj...@apache.org> Committed: Wed Oct 3 04:20:02 2018 -0700 ---------------------------------------------------------------------- .../UnsafeArrayDataBenchmark-results.txt | 33 +++++++++ .../benchmark/UnsafeArrayDataBenchmark.scala | 73 ++++++-------------- 2 files changed, 56 insertions(+), 50 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/spark/blob/56741c34/sql/core/benchmarks/UnsafeArrayDataBenchmark-results.txt ---------------------------------------------------------------------- diff --git a/sql/core/benchmarks/UnsafeArrayDataBenchmark-results.txt b/sql/core/benchmarks/UnsafeArrayDataBenchmark-results.txt new file mode 100644 index 0000000..4ecc1f1 --- /dev/null +++ b/sql/core/benchmarks/UnsafeArrayDataBenchmark-results.txt @@ -0,0 +1,33 @@ +================================================================================================ +Benchmark UnsafeArrayData +================================================================================================ + +OpenJDK 64-Bit Server VM 1.8.0_181-b13 on Linux 3.10.0-862.3.2.el7.x86_64 +Intel(R) Xeon(R) CPU E5-2670 v2 @ 2.50GHz +Read UnsafeArrayData: Best/Avg Time(ms) Rate(M/s) Per Row(ns) Relative +------------------------------------------------------------------------------------------------ +Int 233 / 234 718.6 1.4 1.0X +Double 244 / 244 687.0 1.5 1.0X + +OpenJDK 64-Bit Server VM 1.8.0_181-b13 on Linux 3.10.0-862.3.2.el7.x86_64 +Intel(R) Xeon(R) CPU E5-2670 v2 @ 2.50GHz +Write UnsafeArrayData: Best/Avg Time(ms) Rate(M/s) Per Row(ns) Relative +------------------------------------------------------------------------------------------------ +Int 32 / 33 658.6 1.5 1.0X +Double 73 / 75 287.0 3.5 0.4X + +OpenJDK 64-Bit Server VM 1.8.0_181-b13 on Linux 3.10.0-862.3.2.el7.x86_64 +Intel(R) Xeon(R) CPU E5-2670 v2 @ 2.50GHz +Get primitive array from UnsafeArrayData: Best/Avg Time(ms) Rate(M/s) Per Row(ns) Relative +------------------------------------------------------------------------------------------------ +Int 70 / 72 895.0 1.1 1.0X +Double 141 / 143 446.9 2.2 0.5X + +OpenJDK 64-Bit Server VM 1.8.0_181-b13 on Linux 3.10.0-862.3.2.el7.x86_64 +Intel(R) Xeon(R) CPU E5-2670 v2 @ 2.50GHz +Create UnsafeArrayData from primitive array: Best/Avg Time(ms) Rate(M/s) Per Row(ns) Relative +------------------------------------------------------------------------------------------------ +Int 72 / 73 874.7 1.1 1.0X +Double 145 / 146 433.7 2.3 0.5X + + http://git-wip-us.apache.org/repos/asf/spark/blob/56741c34/sql/core/src/test/scala/org/apache/spark/sql/execution/benchmark/UnsafeArrayDataBenchmark.scala ---------------------------------------------------------------------- diff --git a/sql/core/src/test/scala/org/apache/spark/sql/execution/benchmark/UnsafeArrayDataBenchmark.scala b/sql/core/src/test/scala/org/apache/spark/sql/execution/benchmark/UnsafeArrayDataBenchmark.scala index 51ab0e1..79eaeab 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/execution/benchmark/UnsafeArrayDataBenchmark.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/execution/benchmark/UnsafeArrayDataBenchmark.scala @@ -19,20 +19,21 @@ package org.apache.spark.sql.execution.benchmark import scala.util.Random -import org.apache.spark.benchmark.Benchmark +import org.apache.spark.benchmark.{Benchmark, BenchmarkBase} import org.apache.spark.sql.catalyst.encoders.ExpressionEncoder -import org.apache.spark.sql.catalyst.expressions.{UnsafeArrayData, UnsafeRow} -import org.apache.spark.sql.catalyst.expressions.codegen.{BufferHolder, UnsafeArrayWriter} +import org.apache.spark.sql.catalyst.expressions.UnsafeArrayData /** * Benchmark [[UnsafeArrayDataBenchmark]] for UnsafeArrayData - * To run this: - * 1. replace ignore(...) with test(...) - * 2. build/sbt "sql/test-only *benchmark.UnsafeArrayDataBenchmark" - * - * Benchmarks in this file are skipped in normal builds. + * To run this benchmark: + * {{{ + * 1. without sbt: bin/spark-submit --class <this class> <spark sql test jar> + * 2. build/sbt "sql/test:runMain <this class>" + * 3. generate result: SPARK_GENERATE_BENCHMARK_FILES=1 build/sbt "sql/test:runMain <this class>" + * Results will be written to "benchmarks/UnsafeArrayDataBenchmark-results.txt". + * }}} */ -class UnsafeArrayDataBenchmark extends BenchmarkWithCodegen { +object UnsafeArrayDataBenchmark extends BenchmarkBase { def calculateHeaderPortionInBytes(count: Int) : Int = { /* 4 + 4 * count // Use this expression for SPARK-15962 */ @@ -77,18 +78,10 @@ class UnsafeArrayDataBenchmark extends BenchmarkWithCodegen { } } - val benchmark = new Benchmark("Read UnsafeArrayData", count * iters) + val benchmark = new Benchmark("Read UnsafeArrayData", count * iters, output = output) benchmark.addCase("Int")(readIntArray) benchmark.addCase("Double")(readDoubleArray) benchmark.run - /* - OpenJDK 64-Bit Server VM 1.8.0_91-b14 on Linux 4.4.11-200.fc22.x86_64 - Intel Xeon E3-12xx v2 (Ivy Bridge) - Read UnsafeArrayData: Best/Avg Time(ms) Rate(M/s) Per Row(ns) Relative - ------------------------------------------------------------------------------------------------ - Int 252 / 260 666.1 1.5 1.0X - Double 281 / 292 597.7 1.7 0.9X - */ } def writeUnsafeArray(iters: Int): Unit = { @@ -121,18 +114,10 @@ class UnsafeArrayDataBenchmark extends BenchmarkWithCodegen { doubleTotalLength = len } - val benchmark = new Benchmark("Write UnsafeArrayData", count * iters) + val benchmark = new Benchmark("Write UnsafeArrayData", count * iters, output = output) benchmark.addCase("Int")(writeIntArray) benchmark.addCase("Double")(writeDoubleArray) benchmark.run - /* - OpenJDK 64-Bit Server VM 1.8.0_91-b14 on Linux 4.4.11-200.fc22.x86_64 - Intel Xeon E3-12xx v2 (Ivy Bridge) - Write UnsafeArrayData: Best/Avg Time(ms) Rate(M/s) Per Row(ns) Relative - ------------------------------------------------------------------------------------------------ - Int 196 / 249 107.0 9.3 1.0X - Double 227 / 367 92.3 10.8 0.9X - */ } def getPrimitiveArray(iters: Int): Unit = { @@ -167,18 +152,11 @@ class UnsafeArrayDataBenchmark extends BenchmarkWithCodegen { doubleTotalLength = len } - val benchmark = new Benchmark("Get primitive array from UnsafeArrayData", count * iters) + val benchmark = + new Benchmark("Get primitive array from UnsafeArrayData", count * iters, output = output) benchmark.addCase("Int")(readIntArray) benchmark.addCase("Double")(readDoubleArray) benchmark.run - /* - OpenJDK 64-Bit Server VM 1.8.0_91-b14 on Linux 4.4.11-200.fc22.x86_64 - Intel Xeon E3-12xx v2 (Ivy Bridge) - Get primitive array from UnsafeArrayData: Best/Avg Time(ms) Rate(M/s) Per Row(ns) Relative - ------------------------------------------------------------------------------------------------ - Int 151 / 198 415.8 2.4 1.0X - Double 214 / 394 293.6 3.4 0.7X - */ } def putPrimitiveArray(iters: Int): Unit = { @@ -209,24 +187,19 @@ class UnsafeArrayDataBenchmark extends BenchmarkWithCodegen { doubleTotalLen = len } - val benchmark = new Benchmark("Create UnsafeArrayData from primitive array", count * iters) + val benchmark = + new Benchmark("Create UnsafeArrayData from primitive array", count * iters, output = output) benchmark.addCase("Int")(createIntArray) benchmark.addCase("Double")(createDoubleArray) benchmark.run - /* - OpenJDK 64-Bit Server VM 1.8.0_91-b14 on Linux 4.4.11-200.fc22.x86_64 - Intel Xeon E3-12xx v2 (Ivy Bridge) - Create UnsafeArrayData from primitive array: Best/Avg Time(ms) Rate(M/s) Per Row(ns) Relative - ------------------------------------------------------------------------------------------------ - Int 206 / 211 306.0 3.3 1.0X - Double 232 / 406 271.6 3.7 0.9X - */ } - ignore("Benchmark UnsafeArrayData") { - readUnsafeArray(10) - writeUnsafeArray(10) - getPrimitiveArray(5) - putPrimitiveArray(5) + override def runBenchmarkSuite(): Unit = { + runBenchmark("Benchmark UnsafeArrayData") { + readUnsafeArray(10) + writeUnsafeArray(10) + getPrimitiveArray(5) + putPrimitiveArray(5) + } } } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@spark.apache.org For additional commands, e-mail: commits-h...@spark.apache.org