CHAPTER 3 CACHING AND MEMOIZATION

We saw in Section 1.8 that a natural recursive function can sometimes perform extremely badly. An easy and general solution to many of these performance problems, as well as some that arise in nonrecursive contexts, is caching.

Let’s consider a program that converts images from one format to another. Specifically, let’s imagine that the input is in the popular GIF format, and that the output is something we’re going to send to the printer. The printer is not the little machine that sits on your desk; it’s a big company with giant printing presses that will print one million copies of some magazine by Thursday afternoon.

The printer wants the images in a special CMYK format. CMYK stands for “Cyan-Magenta-Yellow-Black,” ...

Get Higher-Order Perl now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.