Skip to content

Instantly share code, notes, and snippets.

@PeteGabriel
Created May 20, 2018 14:16
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 PeteGabriel/1baa398963c46cc16a26c0520559934b to your computer and use it in GitHub Desktop.
Save PeteGabriel/1baa398963c46cc16a26c0520559934b to your computer and use it in GitHub Desktop.
Measure time in Scala
object Time {
def time[A](a: => A) = {
val now = System.nanoTime
val result = a
val micros = (System.nanoTime - now) / 1000
println("%d microseconds".format(micros))
result
}
// use it like: time { fn() }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment