Last active
December 14, 2015 19:29
-
-
Save artgon/5136878 to your computer and use it in GitHub Desktop.
Parallel collections -- a thing. Results: .....
Series took 100402ms.
.....
Parallel took 12868ms.
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.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