diff options
-rw-r--r-- | sql/core/src/main/scala/org/apache/spark/sql/SparkSession.scala | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/sql/core/src/main/scala/org/apache/spark/sql/SparkSession.scala b/sql/core/src/main/scala/org/apache/spark/sql/SparkSession.scala index 08d74ac018..f3dde480ea 100644 --- a/sql/core/src/main/scala/org/apache/spark/sql/SparkSession.scala +++ b/sql/core/src/main/scala/org/apache/spark/sql/SparkSession.scala @@ -618,6 +618,22 @@ class SparkSession private( @InterfaceStability.Evolving def readStream: DataStreamReader = new DataStreamReader(self) + /** + * Executes some code block and prints to stdout the time taken to execute the block. This is + * available in Scala only and is used primarily for interactive testing and debugging. + * + * @since 2.1.0 + */ + @InterfaceStability.Stable + def time[T](f: => T): T = { + val start = System.nanoTime() + val ret = f + val end = System.nanoTime() + // scalastyle:off println + println(s"Time taken: ${(end - start) / 1000 / 1000} ms") + // scalastyle:on println + ret + } // scalastyle:off // Disable style checker so "implicits" object can start with lowercase i |