Github user rxin commented on a diff in the pull request:

    https://github.com/apache/spark/pull/12087#discussion_r58643458
  
    --- Diff: 
sql/core/src/test/scala/org/apache/spark/sql/DatasetBenchmark.scala ---
    @@ -0,0 +1,85 @@
    +/*
    + * 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
    +
    +import org.apache.spark.SparkContext
    +import org.apache.spark.sql.types.StringType
    +import org.apache.spark.util.Benchmark
    +
    +/**
    + * Benchmark for Dataset typed operations comparing with DataFrame and RDD 
versions.
    + */
    +object DatasetBenchmark {
    +
    +  case class Data(l: Long, s: String)
    +
    +  def main(args: Array[String]): Unit = {
    +    val sparkContext = new SparkContext("local[*]", "Dataset benchmark")
    +    val sqlContext = new SQLContext(sparkContext)
    +
    +    import sqlContext.implicits._
    +
    +    val numRows = 10000000
    +    val df = sqlContext.range(1, numRows).select($"id".as("l"), 
$"id".cast(StringType).as("s"))
    +
    +    val benchmark = new Benchmark("back-to-back map", numRows)
    +
    +    val scalaFunc = (d: Data) => Data(d.l + 1, d.s)
    +    benchmark.addCase("Dataset") { iter =>
    +      var res = df.as[Data]
    +      var i = 0
    +      while (i < 10) {
    +        res = res.map(scalaFunc)
    +        i += 1
    +      }
    +      res.queryExecution.toRdd.foreach(_ => Unit)
    +    }
    +
    +    benchmark.addCase("DataFrame") { iter =>
    +      var res = df
    +      var i = 0
    +      while (i < 10) {
    +        res = res.select($"l" + 1 as "l")
    +        i += 1
    +      }
    +      res.queryExecution.toRdd.foreach(_ => Unit)
    +    }
    +
    +    val rdd = sparkContext.range(1, numRows).map(l => Data(l, l.toString))
    +    benchmark.addCase("RDD") { iter =>
    +      var res = rdd
    +      var i = 0
    +      while (i < 10) {
    +        res = rdd.map(scalaFunc)
    +        i += 1
    +      }
    +      res.foreach(_ => Unit)
    +    }
    +
    +    /*
    +    Java HotSpot(TM) 64-Bit Server VM 1.8.0_60-b27 on Mac OS X 10.11.4
    +    Intel(R) Core(TM) i7-4960HQ CPU @ 2.60GHz
    +    back-to-back map:                   Best/Avg Time(ms)    Rate(M/s)   
Per Row(ns)   Relative
    +    
-------------------------------------------------------------------------------------------
    +    Dataset                                   902 /  995         11.1      
    90.2       1.0X
    +    DataFrame                                 132 /  167         75.5      
    13.2       6.8X
    +    RDD                                       216 /  237         46.3      
    21.6       4.2X
    --- End diff --
    
    cc @marmbrus not part of this pr, but can we reuse the same object in 
dataset?


---
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