% perl -le '$s = q{x} x 1000000 ; $s =~ s/(.{1,50})/$1\n/g; print $s ' > test.txt
% cat hoge.pl
use Benchmark qw( timethese cmpthese ) ;
cmpthese timethese ( undef, {
arr => sub { open my $fh, q{<}, q{test.txt} ; my @arr = <$fh> ; close $fh ; @arr },
whi => sub { open my $fh, q{<}, q{test.txt} ; my @arr ; while (<$fh>){ push @arr, $_ } close $fh ; @arr },
aho => sub { open my $fh, q{<}, q{test.txt} ; my @arr ; for (<$fh>){ push @arr, $_ } close $fh ; @arr },
});
% perl hoge.pl
Benchmark: running aho, arr, whi for at least 3 CPU seconds...
aho: 3 wallclock secs ( 2.76 usr + 0.35 sys = 3.11 CPU) @ 48.87/s (n=152)
arr: 3 wallclock secs ( 2.72 usr + 0.41 sys = 3.13 CPU) @ 56.55/s (n=177)
whi: 3 wallclock secs ( 2.85 usr + 0.30 sys = 3.15 CPU) @ 70.79/s (n=223)
Rate aho arr whi
aho 48.9/s -- -14% -31%
arr 56.5/s 16% -- -20%
whi 70.8/s 45% 25% --