I have a bunch of data files where each line represents a data point.
It's nice to be able to quickly tell how many data points I 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 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
larger data sets, I was getting tired of waiting for wc, and I wondered
whether ByteString.Lazy could help me do better. So I wrote a 2-liner:<br>
<br>
import qualified Data.ByteString.Lazy.Char8 as L<br>
main = L.getContents &gt;&gt;= print . L.count '\n'<br>
<br>
... and compiled this as &quot;lc&quot;. It doesn't get much simpler than 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 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 part.
Granted, wc is doing more work, but the number of words and characters
aren't interesting to me in this case, anyway. I can't imagine
(implementation time)*(execution time) being much shorter. Thanks, Don!<br>
<br>-- <br><br>Chad Scherrer<br><br>&quot;Time flies like an arrow; fruit flies like a banana&quot; -- Groucho Marx