Skip to content

Instantly share code, notes, and snippets.

@daros
Created February 16, 2011 15:26
Show Gist options
  • Save daros/829556 to your computer and use it in GitHub Desktop.
Save daros/829556 to your computer and use it in GitHub Desktop.
Scala paralell test
case class Call(i: Int) {
def call ={
var sleep = 100 + scala.util.Random.nextInt(10)
Thread.sleep(sleep)
println(i)
sleep
}
}
val list = (1 to 100).toArray.map(new Call(_))
val lpar = list.par
def run(list: Seq[Call]) {
var start = System.currentTimeMillis
println("start Seq")
var w = list.map(_.call).foldLeft(0)(_+_)
println("run time: " + (System.currentTimeMillis - start)+" total wait: "+w)
}
run(list)
run(lpar)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment