Skip to content

Instantly share code, notes, and snippets.

@lamdor
Created October 14, 2009 19:52
Show Gist options
  • Select an option

  • Save lamdor/210351 to your computer and use it in GitHub Desktop.

Select an option

Save lamdor/210351 to your computer and use it in GitHub Desktop.
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