Profile Haskell without installing profiling libraries for all dependencies

A good way to circumvent having to compile everything with profiling is to use cabal sandbox. It allows you to set up a sandbox for one application only, and thereby you won't have to re-install your entire ~/.cabal prefix. You'll need a recent version of Cabal, so run cabal update && cabal install cabal-install first.

Once you initialise a sandbox, create a file cabal.config to include the necessary directives (in your case library-profiling: True; executable-profiling: True may also be handy.)

A side-effect of this is that you can test your code with dependencies that need not be installed globally, for example, experimental versions, or outdated versions.

EDIT: btw, I don't think you need to have profiling enabled for criterion to work. In any case, it works for me without profiling being enabled. Just write a Main module that contains main = defaultMain benchmarks where benchmarks has type [Benchmark], i.e. a list of benchmarks that you've written.

You then compile that file (say, we call it benchmarks.hs with ghc --make -o bench benchmarks.hs, and run the program, ./bench with the appropriate arguments (consult the criterion documentation for details. A good default argument is, say ./bench -o benchmarks.html which will generate a nifty report similar to this one)


I had the same problem this week, and although I had recompiled everything by hand, I was instructed in the IRC channel to do the following:

  1. Go to your cabal config file (in case you don't know where)
  2. Edit the line for enable library profiling (and while you are at it, enable documentation)
  3. Run Cabal Install World