No. I suppose "man wc" would have helped, but this has been entertaining, anyway. <br>
Times for lc and wc -l seem comparable over a couple of runs. So in any
case, it's encouraging that it's so easy to reach speeds comparable to
(presumably) highly-tuned C code like this.<br><br>
-Chad<br>
<br><div><span class="gmail_quote">On 6/29/06, <b class="gmail_sendername">Robby Findler</b> <<a href="mailto:robby@cs.uchicago.edu">robby@cs.uchicago.edu</a>> wrote:</span><blockquote style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;" class="gmail_quote">
Just out of curiosity, did you try "wc -l"?<br><br>Robby<br><br>On Jun 29, 2006, at 1:18 PM, Chad Scherrer wrote:<br><br>> I have a bunch of data files where each line represents a data<br>> point. It's nice to be able to quickly tell how many data points I
<br>> have. I had been using wc, like this:<br>><br>> % cat *.txt | /usr/bin/time wc<br>> 2350570 4701140 49149973<br>> 5.81user 0.03system 0:06.08elapsed 95%CPU (0avgtext+0avgdata<br>> 0maxresident)k<br>
> 0inputs+0outputs (152major+18minor)pagefaults 0swaps<br>><br>> I only really care about the line count and the time it takes. For<br>> larger data sets, I was getting tired of waiting for wc, and I<br>> wondered whether
ByteString.Lazy could help me do better. So I<br>> wrote a 2-liner:<br>><br>> import qualified Data.ByteString.Lazy.Char8 as L<br>> main = L.getContents >>= print . L.count '\n'<br>><br>> ... and compiled this as "lc". It doesn't get much simpler than
<br>> that. How does it perform?<br>><br>> % cat *.txt | /usr/bin/time lc<br>> 2350570<br>> 0.09user 0.13system 0:00.24elapsed 89%CPU (0avgtext+0avgdata<br>> 0maxresident)k<br>> 0inputs+0outputs (199major+211minor)pagefaults 0swaps
<br>><br>> Wow. 64 times as fast for this run, with almost no effort on my<br>> part. Granted, wc is doing more work, but the number of words and<br>> characters aren't interesting to me in this case, anyway. I can't
<br>> imagine (implementation time)*(execution time) being much shorter.<br>> Thanks, Don!<br>><br>> --<br>><br>> Chad Scherrer<br>><br>> "Time flies like an arrow; fruit flies like a banana" -- Groucho Marx
<br>> _______________________________________________<br>> Haskell mailing list<br>> <a href="mailto:Haskell@haskell.org">Haskell@haskell.org</a><br>> <a href="http://www.haskell.org/mailman/listinfo/haskell">
http://www.haskell.org/mailman/listinfo/haskell</a><br><br></blockquote></div><br><br clear="all"><br>-- <br><br>Chad Scherrer<br><br>"Time flies like an arrow; fruit flies like a banana" -- Groucho Marx