|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +package org.apache.spark.sql.execution.benchmark |
| 19 | + |
| 20 | +import org.apache.spark.benchmark.Benchmark |
| 21 | +import org.apache.spark.sql.internal.SQLConf |
| 22 | + |
| 23 | +/** |
| 24 | + * Benchmark to measure performance for wide table. |
| 25 | + * {{{ |
| 26 | + * To run this benchmark: |
| 27 | + * 1. without sbt: bin/spark-submit --class <this class> |
| 28 | + * --jars <spark core test jar>,<spark catalyst test jar> <spark sql test jar> |
| 29 | + * 2. build/sbt "sql/test:runMain <this class>" |
| 30 | + * 3. generate result: SPARK_GENERATE_BENCHMARK_FILES=1 build/sbt "sql/test:runMain <this class>" |
| 31 | + * Results will be written to "benchmarks/WideTableBenchmark-results.txt". |
| 32 | + * }}} |
| 33 | + */ |
| 34 | +object WideTableBenchmark extends SqlBasedBenchmark { |
| 35 | + |
| 36 | + override def runBenchmarkSuite(mainArgs: Array[String]): Unit = { |
| 37 | + runBenchmark("projection on wide table") { |
| 38 | + val N = 1 << 20 |
| 39 | + val df = spark.range(N) |
| 40 | + val columns = (0 until 400).map{ i => s"id as id$i"} |
| 41 | + val benchmark = new Benchmark("projection on wide table", N, output = output) |
| 42 | + Seq("10", "100", "1024", "2048", "4096", "8192", "65536").foreach { n => |
| 43 | + benchmark.addCase(s"split threshold $n", numIters = 5) { iter => |
| 44 | + withSQLConf(SQLConf.CODEGEN_METHOD_SPLIT_THRESHOLD.key -> n) { |
| 45 | + df.selectExpr(columns: _*).foreach(identity(_)) |
| 46 | + } |
| 47 | + } |
| 48 | + } |
| 49 | + benchmark.run() |
| 50 | + } |
| 51 | + } |
| 52 | +} |
0 commit comments