Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: How To Count Lines In File?

by jmcnamara (Monsignor)
on Jan 27, 2003 at 00:00 UTC ( [id://230081]=note: print w/replies, xml ) Need Help??


in reply to How To Count Lines In File?


The FAQ method is more efficient because it is reading in fixed block sizes which it doesn't have to split into lines.

Here is a benchmark to show the difference. I added wc for comparison:

$ time wc -l bigfile 91420 bigfile real 0m0.016s user 0m0.010s sys 0m0.006s $ time perl faq.pl bigfile 91420 real 0m0.032s user 0m0.027s sys 0m0.004s $ time perl cody.pl bigfile 91420 real 0m0.105s user 0m0.098s sys 0m0.008s

Here is the way I usually don't do it, this is twice as slow as the slowest method above:     perl -le 'print $==()=<>' file

--
John.

Update: Added benchmark.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://230081]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2024-04-25 19:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found