Profiling Haskell programs

A quick 101 on profiling Haskell programs


  • criterion

    Benchmark functions, note that you have to be mindful of laziness, otherwise you might not force a result out of the function.

  • threadscope

    Profile runtime heap allocation

  • speedscope

    Profile runtime costs of each function. Note ordering might be ambiguous at times, although mostly accurate. I encountered issues when dealing with Lazy IO.

General setup

Single file just use ghc profiling flags.

For heap profiling, i.e. via threadscope, make sure to add -eventlog when compiling and +RTS -l rts option during runtime.

You can specify these in cabal file if you’re using cabal / stack.


Read the ghc profiling guide.

Ask on Stack Overflow.

Small PoCs to understand behaviour before benchmarking the entire app.