Created
April 24, 2019 06:42
-
-
Save raidery/0326544f0994c0c6e2a103ff7c3108e5 to your computer and use it in GitHub Desktop.
averageTime block with Scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def averageTime[R](block: => R, numIter: Int = 10): Unit = { | |
val t0 = System.nanoTime() | |
(1 to numIter).foreach( _ => block) | |
val t1 = System.nanoTime() | |
val averageTimeTaken = (t1 - t0) / numIter | |
val timeTakenMs = averageTimeTaken / 1000000 | |
println("Elapsed time: " + timeTakenMs + "ms") | |
} | |
val testDf = spark.range(10000000).toDF.cache | |
val resultSparkNative = testDf.withColumn("addOne", 'id + 1) | |
scala> averageTime { resultSparkNative.count } | |
Elapsed time: 36ms |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment