Last active
December 14, 2015 17:09
-
-
Save jamesthompson/5120519 to your computer and use it in GitHub Desktop.
Scala Implicit Timer
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
implicit class Timer[T](f: => T) { | |
def timems = { | |
val before = System.currentTimeMillis | |
val result = f | |
val end = System.currentTimeMillis | |
println(s"Operation elapsed time = ${end - before} ms >>> Result = $result") | |
} | |
def timens = { | |
val before = System.nanoTime | |
val result = f | |
val end = System.nanoTime | |
println(s"Operation elapsed time = ${(end - before) / 1e6} ms >>> Result = $result") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment