Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

(RhetTbull) Re: Looking for a better way to get the number of lines in a file...

by RhetTbull (Curate)
on Dec 10, 2001 at 18:06 UTC ( [id://130658]=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    while (<FILE>){};
    print "length = $.";
    
  2. or download this
    #!/usr/bin/perl
    
    ...
                    close(INFILE);
            }
    });
    
  3. or download this
    Benchmark: timing 100 iterations of chunk, line_by_line...
         chunk:  3 wallclock secs ( 1.58 usr +  0.70 sys =  2.28 CPU) @ 43
    +.80/s (n=100)
         line_by_line: 12 wallclock secs ( 9.54 usr +  0.72 sys = 10.27 CP
    +U) @  9.74/s (n=100)
    
  4. or download this
    open INFILE,'test.dat' or die "open: $!";
    my $count = 0;
    while (sysread(INFILE,$_,102400)) { $count += tr/\n//; }
    
  5. or download this
    /home/rhet/misc> ./testfcount.pl
    Benchmark: timing 100 iterations of chunk, line_by_line, sysread...
         chunk: 12 wallclock secs ( 8.00 usr +  3.52 sys = 11.53 CPU) @  8
    +.68/s (n=100)
         line_by_line: 154 wallclock secs (149.20 usr +  3.29 sys = 152.50
    + CPU) @  0.66/s (n=100)
         sysread:  6 wallclock secs ( 4.09 usr +  1.62 sys =  5.71 CPU) @ 
    +17.52/s (n=100)
    

Log In?
Username:
Password:

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

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

    No recent polls found