Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added example for parallel collection

  • Loading branch information...
commit d523cac75e2e05cc4d5ab539b8e5b324627cebee 1 parent cf195c3
@nraychaudhuri authored
Showing with 26 additions and 0 deletions.
  1. +26 −0 chap04/ParallelCollections.scala
View
26 chap04/ParallelCollections.scala
@@ -0,0 +1,26 @@
+package chap04
+
+import scala.collection.parallel.immutable._
+
+object ParallelCollectionsExample {
+
+ def parallelFilter = {
+ Vector.range(1, 100000).par.filter(_ % 2 == 0).seq
+ }
+
+ def conversion = {
+ timedOperation {
+ Vector.range(1, 50000).par
+ }
+ timedOperation {
+ val xs = List.iterate(1, 50000)(x => x + 1)
+ xs.par
+ }
+ }
+
+ def timedOperation[T](f: => T) = {
+ val startTime = System.currentTimeMillis
+ f
+ println("Time taken = " + (System.currentTimeMillis - startTime))
+ }
+}

0 comments on commit d523cac

Please sign in to comment.
Something went wrong with that request. Please try again.