Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/13680#discussion_r69372870
  
    --- Diff: 
sql/core/src/test/scala/org/apache/spark/sql/execution/benchmark/UnsafeArrayDataBenchmark.scala
 ---
    @@ -0,0 +1,298 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.spark.sql.execution.benchmark
    +
    +import org.apache.spark.SparkConf
    +import org.apache.spark.sql.catalyst.expressions.{UnsafeArrayData, 
UnsafeRow}
    +import org.apache.spark.sql.catalyst.expressions.codegen.{BufferHolder, 
UnsafeArrayWriter}
    +import org.apache.spark.unsafe.Platform
    +import org.apache.spark.util.Benchmark
    +
    +/**
    + * Benchmark [[UnsafeArrayDataBenchmark]] for UnsafeArrayData
    + * To run this:
    + *  build/sbt "sql/test-only *benchmark.UnsafeArrayDataBenchmark"
    + *
    + * Benchmarks in this file are skipped in normal builds.
    + */
    +class UnsafeArrayDataBenchmark extends BenchmarkBase {
    +
    +  new SparkConf()
    +    .setMaster("local[1]")
    +    .setAppName("microbenchmark")
    +    .set("spark.driver.memory", "3g")
    +
    +  def calculateHeaderPortionInBytes(count: Int) : Int = {
    +    // Use this assignment for SPARK-15962
    +    // val size = 4 + 4 * count
    +    val size = UnsafeArrayData.calculateHeaderPortionInBytes(count)
    +    size
    +  }
    +
    +  def readUnsafeArray(iters: Int): Unit = {
    +    val count = 1024 * 1024 * 16
    +
    +    val intUnsafeArray = new UnsafeArrayData
    +    var intResult: Int = 0
    +    val intSize = calculateHeaderPortionInBytes(count) + 4 * count
    +    val intBuffer = new Array[Byte](intSize)
    +    Platform.putInt(intBuffer, Platform.BYTE_ARRAY_OFFSET, count)
    +    intUnsafeArray.pointTo(intBuffer, Platform.BYTE_ARRAY_OFFSET, intSize)
    +    val readIntArray = { i: Int =>
    +      var n = 0
    +      while (n < iters) {
    +        val len = intUnsafeArray.numElements
    +        var sum = 0.toInt
    +        var i = 0
    +        while (i < len) {
    +          sum += intUnsafeArray.getInt(i)
    +          i += 1
    +        }
    +        intResult = sum
    +        n += 1
    +      }
    +    }
    +
    +    val doubleUnsafeArray = new UnsafeArrayData
    +    var doubleResult: Double = 0
    +    val doubleSize = calculateHeaderPortionInBytes(count) + 8 * count
    +    val doubleBuffer = new Array[Byte](doubleSize)
    +    Platform.putInt(doubleBuffer, Platform.BYTE_ARRAY_OFFSET, count)
    +    doubleUnsafeArray.pointTo(doubleBuffer, Platform.BYTE_ARRAY_OFFSET, 
doubleSize)
    +    val readDoubleArray = { i: Int =>
    +      var n = 0
    +      while (n < iters) {
    +        val len = doubleUnsafeArray.numElements
    +        var sum = 0.toDouble
    +        var i = 0
    +        while (i < len) {
    +          sum += doubleUnsafeArray.getDouble(i)
    +          i += 1
    +        }
    +        doubleResult = sum
    +        n += 1
    +      }
    +    }
    +
    +    val benchmark = new Benchmark("Read UnsafeArrayData", count * iters)
    +    benchmark.addCase("Int")(readIntArray)
    +    benchmark.addCase("Double")(readDoubleArray)
    +    benchmark.run
    +    /*
    +    Without SPARK-15962
    +    OpenJDK 64-Bit Server VM 1.8.0_91-b14 on Linux 4.0.4-301.fc22.x86_64
    +    Intel Xeon E3-12xx v2 (Ivy Bridge)
    +    Read UnsafeArrayData:                    Best/Avg Time(ms)    
Rate(M/s)   Per Row(ns)   Relative
    +    
------------------------------------------------------------------------------------------------
    +    Int                                            370 /  471        454.0 
          2.2       1.0X
    +    Double                                         351 /  466        477.5 
          2.1       1.1X
    +    */
    +    /*
    +    With SPARK-15962
    --- End diff --
    
    only put the current result here, i.e. with this PR. and put the result 
without this PR in PR comment.
    
    A benchmark is used to show the performance of current code, not the 
improvement for some patches, or it will be very hard to maintain.(think about 
if we improve unsafe array again in the future, how should we update this 
benchmark?)


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to