Small Messages, Big Computations

We’ve talked theory; now for some measurements. In this section, we’ll perform two experiments. We’ll map two functions over a list of a hundred elements, and we’ll compare the time it takes with a parallel map vs. a sequential map.

We’ll use two different problem sets. The first computes this:

 
L = [L1, L2, ..., L100],
 
map(​fun​ lists:sort/1, L)

Each of the elements in L is a list of 1,000 random integers.

The second computes this:

 
L = [27,27,..., 27],
 
map(​fun​ ptests:fib/1, L)

Here, L is a list of one hundred 27s, and we compute the list [fib(27), fib(27), ...] one hundred times. (fib is the Fibonacci function.)

We’ll time both these functions. Then we’ll replace map with pmap and repeat the timings. ...

Get Programming Erlang, 2nd Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.