On 10/17/07, <b class="gmail_sendername">Thomas Hartman</b> <<a href="mailto:thomas.hartman@db.com">thomas.hartman@db.com</a>> wrote:<div><span class="gmail_quote"></span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<font face="sans-serif" size="2"></font><br><font face="sans-serif" size="2">Is there a more scientific way of figuring
out if one version is better than the other by using, say profiling tools?</font></blockquote><div><br>Profiling Haskell programs is black magic, but of the sort you learn by having a problem to solve. I don't think it requires special genius, just enough motivation. Profiling the interpreter my team created during the ICFP contest did that to me.
<br><br>The GHC heap profiler looked weird to me at first because you are required to convert its output to a PostScript file. However, it's well worth doing. There are several types of profiles, but you would probably be most interested in the "biographical" profile. The GHC documentation is pretty good and the article "Heap Profiling for Space Efficiency"[1] may also help. The article was written for the nhc compiler but the tools look the same.
<br><br>Performance profiling is easier - it's just dumped as text output when your program runs. GHC's documentation is really good here. One thing I've learned is to look for two things:<br><br> 1) Functions that do allocations and execute many times
<br> 2) Functions that run lots of times<br><br>#2 is pretty much universal for profiling, but #1 is unique to Haskell (and probably any pure functional language).<br><br>Sadly none of these technique work for stack overflows. Or, more likely, I haven't learned how to spot them. Luckily the culprit is usually a fold that isn't strict enough. Albert's post about the Bird book is a good pointer. I just read that chapter myself last night, and he gives a very clear explanation of how lazy evaluation works (he calls it 'outermost reduction') and how strictness interacts with laziness.
<br><br>Hope that helps!<br><br>Justin<br><br>[1] <a href="http://citeseer.ist.psu.edu/runciman96heap.html">http://citeseer.ist.psu.edu/runciman96heap.html</a><br><br><br></div></div>