Skip to content

Instantly share code, notes, and snippets.

@mikem
Created September 6, 2016 01:50
Show Gist options
  • Save mikem/405f4d5115f2f372b207998649754eb6 to your computer and use it in GitHub Desktop.
Save mikem/405f4d5115f2f372b207998649754eb6 to your computer and use it in GitHub Desktop.
Timing code in Scala
// see http://stackoverflow.com/a/9160068/2576
def time[R](block: => R): R = {
val t0 = System.nanoTime()
val result = block // call-by-name
val t1 = System.nanoTime()
println("Elapsed time: " + (t1 - t0) + "ns")
result
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment