Skip to content

Instantly share code, notes, and snippets.

@nicerobot
Created December 5, 2012 07:07
Show Gist options
  • Save nicerobot/4213299 to your computer and use it in GitHub Desktop.
Save nicerobot/4213299 to your computer and use it in GitHub Desktop.
Learning a language will help you know how to use the language :P

There's plenty of rebuttal/criticism to http://beust.com/weblog/2011/08/15/scalas-parallel-collections/

I feel I'm still learning Scala so I wanted to just test my own criticisms before reading the comments.

It seems such a well-seasons Java developer would not have overlooked the obvious flaws in his arguments. This was really obvious to me but i have gone through Martin's https://class.coursera.org/progfun-2012-001/lecture/index

Run

curl -kLs https://raw.github.com/gist/4213299/batch.par.scala | scala; stty echo
// I think this is how to "batch" things to run in parallel.
// That is, limit the concurrency of a large collection.
object Batch {
def run(c:Int = 20, threads:Int = 10) = (c to 1 by -1).groupBy(_%threads).map(x => x._2.par.map(t(x._1)))
// This is just a helper function to show what is being run in which thread and how long it takes.
def t(x:Int)(a:Int) = {
val b = System.currentTimeMillis
Thread.sleep(a*10);
val c = System.currentTimeMillis
(x,Thread.currentThread.getId,a,b,c,(c-b))
}
}
for { x <- Batch.run() } println(x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment