Skip to content

Instantly share code, notes, and snippets.

@kafecho
Created March 24, 2013 16:27
Show Gist options
  • Save kafecho/5232545 to your computer and use it in GitHub Desktop.
Save kafecho/5232545 to your computer and use it in GitHub Desktop.
Using timeThis
val n = 40
// Measure in milliseconds how long it takes to compute a Fibonacci sequence.
timeThis(msecs){
println ("Naive recursion fib of " + n + ": " + fib(n))
}
// Measure in nanoseconds how long it takes to compute a Fibonacci sequence.
timeThis(nanosecs){
println ("Tail recursion fib of " + n + ": " + fib2(n))
}
// If you don't specify a time unit, it defaults to milliseconds.
timeThis{
println ("I am going to sleep...")
Thread.sleep(1000)
println("Nice to wake up")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment