Skip to content

Instantly share code, notes, and snippets.

@artgon
Last active December 14, 2015 19:29
Show Gist options
  • Save artgon/5136878 to your computer and use it in GitHub Desktop.
Save artgon/5136878 to your computer and use it in GitHub Desktop.
Parallel collections -- a thing. Results: ..... Series took 100402ms. ..... Parallel took 12868ms.
import scala.collection.parallel.immutable.ParRange
object Parallel extends App {
val bigSet = 1 to 500
val start = System.currentTimeMillis()
bigSet.foreach { i =>
Thread.sleep(200)
if (i % 100 == 0) print(".")
}
println("\nSeries took %sms.".format((System.currentTimeMillis() - start)))
val start2 = System.currentTimeMillis()
new ParRange(bigSet).foreach { i =>
Thread.sleep(200)
if (i % 100 == 0) print(".")
}
println("\nParallel took %sms.".format((System.currentTimeMillis() - start2)))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment