Skip to content

Instantly share code, notes, and snippets.

@wolkym
Created July 31, 2015 14:18
Show Gist options
  • Save wolkym/ef4991f8af5de8094f8c to your computer and use it in GitHub Desktop.
Save wolkym/ef4991f8af5de8094f8c to your computer and use it in GitHub Desktop.
timing scala execution
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
}
// Now wrap your method calls, for example change this...
val result = 1 to 1000 sum
// ... into this
val result = time { 1 to 1000 sum }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment