Created
March 24, 2013 16:27
-
-
Save kafecho/5232545 to your computer and use it in GitHub Desktop.
Using timeThis
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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