[Haskell-beginners] profiling in haskell

Justin Bailey jgbailey at gmail.com
Fri Aug 29 00:11:36 EDT 2008

On Thu, Aug 28, 2008 at 3:37 PM, Vlad Skvortsov <vss at 73rus.com> wrote:
> Hi!
> I'm trying to profile the code pasted below. Per the profiler output it
> takes about 30% of my program running time and I'd like to analyze it
> further. What I need is a breakdown on a finer level, so I inserted SCC
> annotations. However, they appear to have attributed zero cost. I use GHC
> 6.8.2 on FreeBSD, the code is compiled without -O options.
> What am I doing wrong?

You need more SCC annotations.

> Note: I'm not trying to *optimize* this code (I intuitively know where the
> problems are). My intention is to learn the mechanics of profiling Haskell
> code.

Are you sure? Lazy evaluation is tricky. Try adding an SCC annotation
to each function. E.g.:

>   dumpWith f = {-# SCC 'fold' #-} Data.Map.foldWithKey f []
>     docToStr k (Doc { docName=n, docVectorLength=vl}) =
>     {-# SCC 'docToStr' #-}  (:) ("d " ++ show k ++ " " ++ n ++ " " ++ (show vl))

The call stack will then help you determine which invocation of the
given function is taking up the time. Or it may be somewhere else.

The Real World Haskell chapter on profiling is a good guide:



More information about the Beginners mailing list