Using parallel collections
Most of the concurrent programming utilities we have studied so far are used in order to enable different threads of computation to exchange information. Atomic variables, the synchronized
statement, concurrent queues, futures, and promises are focused on ensuring the correctness of a concurrent program. On the other hand, the parallel collection programming model is designed to be largely identical to that of sequential Scala collections; parallel collections exist solely in order to improve the running time of the program. In this chapter, we will measure the relative speedup of programs using parallel collections. To make this task easier, we will introduce the timed
method to the package object used for the examples in this chapter. This method takes a block of code body, and returns the running time of the executing block of code body
. It starts by recording the current time with the nanoTime
method from the JDK System
class. It then runs the body, records...