Perlコーディング初心者質問スレ Part 63
■ このスレッドは過去ログ倉庫に格納されています
0167nobodyさん
2011/09/30(金) 19:33:37.65ID:???slurp の方が早いよって主張ならまだしも、、、
>>130の結果が理解出来てないだろお前さん。
% 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 ; printf STDERR "%d\n", scalar @arr ; for ( @arr ){ print STDERR; } },
whi => sub { open my $fh, q{<}, q{test.txt} ; my @arr ; while (<$fh>){ push @arr, $_ } ; close $fh ; printf STDERR "%d\n", $. ; for ( @arr ){ print STDERR; } },
});
% perl hoge.pl 2> /dev/null
Benchmark: running arr, whi for at least 3 CPU seconds...
arr: 4 wallclock secs ( 2.00 usr + 1.23 sys = 3.23 CPU) @ 242.11/s (n=782)
whi: 4 wallclock secs ( 1.95 usr + 1.29 sys = 3.24 CPU) @ 254.94/s (n=826)
Rate arr whi
arr 242/s -- -5%
whi 255/s 5% --
■ このスレッドは過去ログ倉庫に格納されています