Simberon Design Minute
 

Test the Extremes

Recently, I was working with some code that had been written many years ago to download pictures over a socket connection. Even though large pictures were frequently uploaded, there was never any code in place to download the large pictures. Only thumbnails and scaled-down versions of the pictures were ever downloaded. On the theory that it would be useful for users to see the original picture in its full resolution, I implemented a feature to view the original picture. Much to my surprise, it took over a minute to download the large image. Since the upload was quick, I couldn't understand why the download was so slow. After looking into it, I realized that the download routine was receiving packets and allocating a buffer the size of the remaining file on every iteration through the loop. It was the allocation and releasing of this buffer that took all the time. The lesson here is to test the extremes. If your program needs to handle large files, make sure that it works properly on large files. It's easy to test with small samples but you should be sure to include large samples in your tests as well.

Download