<div class="gmail_quote">On Tue, Nov 10, 2009 at 8:20 PM, Gokul P. Nair <span dir="ltr">&lt;<a href="mailto:gpnair78@yahoo.com">gpnair78@yahoo.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td style="font-family: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; font-size: inherit; line-height: inherit; font-size-adjust: inherit; font-stretch: inherit;" valign="top">
<div class="im"><div>--- On Sat, 11/7/09, Don Stewart &lt;<a href="mailto:dons@galois.com" target="_blank">dons@galois.com</a>&gt; wrote:<br>&gt; General notes:<br>&gt;<br>&gt;  * unpack is almost always wrong.<br>&gt;  * list indexing with !! is almost always wrong.<br>
&gt;  * words/lines are often wrong for parsing large files (they build large list structures).<br>&gt;  * toList/fromList probably aren&#39;t the best strategy<br>&gt;  * sortBy (comparing snd)<br>&gt;  * use insertWith&#39;</div>

<div>&gt; Spefically, avoid constructing intermediate lists, when you can process the<br>&gt; entire file in a single pass. Use O(1) bytestring substring operations like<br>&gt; take and drop.</div>
<div> </div>
</div><div>Thanks all for the valuable feedback. Switching from Regex.Posix to Regex.PCRE alone reduced the running time to about 6 secs and a few other optimizations suggested on this thread brought it down to about 5 secs ;) </div>

<div> </div>
<div>I then set out to profile the code out of curiosity to see where the bulk of the time was being spent and sure enough the culprit turned out to be &quot;unpack&quot;. My question therefore is, given a list L1 of type [(ByteString, Int)], how do I print it out so as to eliminate the &quot;chunk, empty&quot; markers associated with a bytestring? The suggestions posted here are along the lines of &quot;mapM_ print L1&quot; but that&#39;s far from desirable especially because the generated output is for perusal by non-technical users etc.</div>

<div> </div>
<div>Thanks.<br></div></td></tr></tbody></table><br></blockquote><div><br>Take a look at Data.ByteString.Lazy.Char8.putStrLn.  That prints a lazy ByteString without unpacking it, and without the internal markers.<br><br>
Sincerely,<br>Brad <br></div></div><br>