February 2014
Intermediate to advanced
160 pages
4h 59m
English
We can easily parallelize the previous example to speed up the execution.
Let’s take a closer look at the code before we make any changes. We send the tickers though the map method, which sequentially invokes the attached function to get the price from Yahoo! Once all the prices arrive, we sequentially trim the list to stocks within the desired price range. In the last step, which is also sequential, we pick the highest priced among them.
Of these three operations, the first is the slowest. It involves a call to the web service, incurs a network delay, and has to perform the operation 20 times—once for each ticker symbol. The remaining operations involve light arithmetic and hardly take any time. Thankfully, in this ...