Created
October 14, 2009 19:52
-
-
Save lamdor/210351 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| import scala.actors.Futures._ | |
| def countdown(n: Int): Unit = if (n > 0) countdown(n-1) | |
| def time(f: => Any) { | |
| val start = System.nanoTime | |
| f | |
| val elapsed = System.nanoTime - start | |
| val elapsedInMillis = elapsed.toDouble / 1000000 | |
| format("Elapsed: %f ms\n", elapsedInMillis) | |
| } | |
| def dotimes[T](n: Int)(f: => T): Array[T] = (for (i <- 1 to n) yield f).toArray | |
| def test() { | |
| time { | |
| val results = dotimes(2) { | |
| future(countdown(100000000)) | |
| } | |
| results.map(f => f.apply()) | |
| } | |
| } | |
| dotimes(20) { | |
| println("-----------") | |
| test() | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment