Skip to content

Instantly share code, notes, and snippets.

@narma
Last active March 7, 2023 22:35
Show Gist options
  • Save narma/5ffa9e9a81aa2c2acd67c2d81ac0949c to your computer and use it in GitHub Desktop.
Save narma/5ffa9e9a81aa2c2acd67c2d81ac0949c to your computer and use it in GitHub Desktop.
def time[R](what: String)(block: => R): R = {
val t0 = java.lang.System.nanoTime()
val result = block
val ms = (java.lang.System.nanoTime() - t0) / 10e5.toInt
println(s"$what completed. Time elapsed: ${ms}ms")
result
}
def t[R](block: => R): R = {
val t0 = java.lang.System.nanoTime()
val result = block
val ms = (java.lang.System.nanoTime() - t0) / 10e5.toInt
println(s"Time elapsed: ${ms}ms")
result
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment