This chapter covers:
- Benchmarking code in Haskell
- Exploring time and space consumption
- Tips and tricks to optimize code
In this chapter, we’ll see how to check the performance of our code. As usual, we’ll be interested in time and space usage characteristics. We’ll discuss how to compare different implementations of the same function in terms of execution time using benchmarking and choose which implementation is the most suitable. We’ll explore time and space consumption of our programs (we call it profiling) and use this information to find drawbacks in the implementation, such as space leaks. Finally, we’ll see how to use benchmarking and profiling to make our programs run faster.
Remember, we’ve already implemented the first version of the IP filtering application and tested it intensively. We’ll continue working on the same project in this chapter. Let’s make some assumptions on how this utility program is intended to be used:
- the list of ranges might be rather big containing thousands of them;
- the ranges database is fixed at runtime, so we don’t have to reload it;
- IP addresses for filtering are processed as they go, there might be millions of them.