Haskell measuring function performance

benchmarking, haskell, profiling

Solution

Measuring how long it takes to run and how much memory it takes are two separate problems, namely: benchmarking and profiling. Haskell has a well defined set of tools for both. Solving neither of the problems requires you to make any changes to the actual application's code.

Benchmarking

This is done using libraries. There is an ultimate winner in that area, which was suggested by Niklas in the comments, namely Criterion. The library is very well designed, isn't hard to use and produces a very detailed data.

The workflow is the following: you create a separate module containing the setup of your benchmark, compile it and run it with options. To get a reference on available options run it with `--help` modifier.

You can find examples of setup modules here.

Profiling

There is enough of good materials on that already, so I'll just refer to them:

- General reference on profiling

- A tutorial in Real World Haskell

- A tutorial on profiling with Cabal

Problem

In Haskell, how can i 'simply' measure a functions performance. For example, how long it takes to run, or how much memory it takes?. I am aware of profiling, however, is there a more simple way that will not require me to change my code too much?

Original source