Created
May 20, 2018 14:16
-
-
Save PeteGabriel/1baa398963c46cc16a26c0520559934b to your computer and use it in GitHub Desktop.
Measure time in 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
object Time { | |
def time[A](a: => A) = { | |
val now = System.nanoTime | |
val result = a | |
val micros = (System.nanoTime - now) / 1000 | |
println("%d microseconds".format(micros)) | |
result | |
} | |
// use it like: time { fn() } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment