while (){}; print "length = $."; #### #!/usr/bin/perl use warnings; use strict; use Benchmark; timethese(100, { 'line_by_line' => q{ open(INFILE,'test.dat') or die "open: $!"; while(){}; close(INFILE); }, 'chunk' => q{ $count = 0; open(INFILE,'test.dat') or die "open: $!"; local $/=\1024000; while() { $count += tr/\n// } close(INFILE); } }); #### 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 CPU) @ 9.74/s (n=100) #### open INFILE,'test.dat' or die "open: $!"; my $count = 0; while (sysread(INFILE,$_,102400)) { $count += tr/\n//; } #### /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)