Skip to content

Instantly share code, notes, and snippets.

@fran0x
Last active June 16, 2016 06:01
Show Gist options
  • Save fran0x/429a8eaf7edb81a42e2663e6c23214c2 to your computer and use it in GitHub Desktop.
Save fran0x/429a8eaf7edb81a42e2663e6c23214c2 to your computer and use it in GitHub Desktop.
Utility code for time measurement
// Measure.time is used to measure the time that takes to complete a block of code (in nanoseconds)
// note: this version does not return the result of calling that function; a different version should be created for that
object Measure {
def time(block: => Unit)={
val s = System.nanoTime
block
System.nanoTime - s
}
}
// example of usage
object Test extends App {
def count(i: Int) = for (j <- 1 to i) {}
import Measure._
println("Elapsed time: " + time(count(10000000)))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment