spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kiszk <...@git.apache.org>
Subject [GitHub] spark pull request #13680: [SPARK-15962][SQL] Introduce implementation with ...
Date Sun, 03 Jul 2016 07:01:01 GMT
Github user kiszk commented on a diff in the pull request:

    https://github.com/apache/spark/pull/13680#discussion_r69386603
  
    --- 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 --
    
    Sure, removed the result without this PR


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


Mime
View raw message