progs/lecture1.scala
changeset 147 72f7dd1a3754
parent 143 11396c17cd8b
child 148 ead6089209ba
--- a/progs/lecture1.scala	Tue Nov 14 22:19:04 2017 +0000
+++ b/progs/lecture1.scala	Fri Nov 17 02:13:40 2017 +0000
@@ -301,44 +301,6 @@
 
 
 
-// Problems with mutability and parallel computations
-//====================================================
-
-def count_intersection(A: Set[Int], B: Set[Int]) : Int = {
-  var count = 0
-  for (x <- A; if (B contains x)) count += 1 
-  count
-}
-
-val A = (1 to 1000).toSet
-val B = (1 to 1000 by 4).toSet
-
-count_intersection(A, B)
-
-// but do not try to add .par to the for-loop above
-
-
-//propper parallel version
-def count_intersection2(A: Set[Int], B: Set[Int]) : Int = 
-	A.par.count(x => B contains x)
-
-count_intersection2(A, B)
-
-
-//for measuring time
-def time_needed[T](n: Int, code: => T) = {
-  val start = System.nanoTime()
-  for (i <- (0 to n)) code
-  val end = System.nanoTime()
-  (end - start) / 1.0e9
-}
-
-val A = (1 to 1000000).toSet
-val B = (1 to 1000000 by 4).toSet
-
-time_needed(10, count_intersection(A, B))
-time_needed(10, count_intersection2(A, B))
-