Skip to content

07 Measuring the execution time

Vladyslav Pekker edited this page Dec 26, 2015 · 11 revisions

⬅️ | ➡️

In the MiscModule spells defines miscellaneous utility methods, which are too small for a distinctive module. Among them is measureExecutionTime[T](expression: => T): (T, Duration):

scala> def fetchTheAnswer(): Int = {
     |   Thread.sleep(3000)
     |
     |   42
     | }
fetchTheAnswer: ()Int

scala> val result @ (theAnswer, duration) = measureExecutionTime(fetchTheAnswer)
result: (Int, scala.concurrent.duration.Duration) = (42,3000178505 nanoseconds)
theAnswer: Int = 42
duration: scala.concurrent.duration.Duration = 3000178505 nanoseconds

⬅️ | ➡️

Clone this wiki locally