Subject: profiling in haskell
From: Vlad Skvortsov <[email-masked]>
To: [email-masked]
Date: Thu, 28 Aug 2008 15:37:56 -0700

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?

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.

serialize :: Database -> [[String]]
serialize (dmap, tmap) =
  [
    {-# SCC "XXX1" #-} [dbFormatTag],
    {-# SCC "XXX2" #-} (dumpWith docToStr dmap),
    {-# SCC "XXX3" #-} (dumpWith termToStr tmap)
  ]
  where
    dumpWith f = Data.Map.foldWithKey f []
   
    docToStr k (Doc { docName=n, docVectorLength=vl}) =
      (:) ("d " ++ show k ++ " " ++ n ++ " " ++ (show vl))

    termToStr t il =
      (:) ("t " ++ t ++ " " ++ (foldl ilItemToStr "" il))

    ilItemToStr acc (docid, weight) =
      show docid ++ ":" ++ show weight ++ " " ++ acc

-- 
Vlad Skvortsov, [email-masked], http://vss.73rus.com