Skip to content

Instantly share code, notes, and snippets.

@jamesthompson
Last active December 14, 2015 17:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamesthompson/5120519 to your computer and use it in GitHub Desktop.
Save jamesthompson/5120519 to your computer and use it in GitHub Desktop.
Scala Implicit Timer
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