I originally got it into my head that setting the size for slurping was a good thing after reading Slurp-Eazy. I seem to recall that it seemed quicker on my old portable under 5.6.1.
However, looking again now under 5.8.4, the picture is both mixed and confusing:
(ordered both ways to eliminate the possibilty of "first run bias")
#! perl -slw
use strict;
use Benchmark qw[ cmpthese ];
open our $raw, '<:raw', $ARGV[ 0 ] or die $!;
open our $txt, '< ', $ARGV[ 0 ] or die $!;
our $s = -s $raw;
cmpthese -3, {
d_raw_trad => q[ my $data = do{ local $/; <$raw> }; ],
c_raw_size => q[ my $data = do{ local $/ = \$s; <$raw> }; ],
b_txt_trad => q[ my $data = do{ local $/; <$txt> }; ],
a_txt_size => q[ my $data = do{ local $/ = \$s; <$txt> }; ],
};
__END__
[15:46:09.53] P:\test>440395 100.dat
Rate raw_size raw_trad txt_trad txt_size
a_raw_size 7969/s -- -87% -88% -96%
b_raw_trad 63136/s 692% -- -2% -69%
c_txt_trad 64282/s 707% 2% -- -69%
d_txt_size 206315/s 2489% 227% 221% --
[15:53:19.11] P:\test>440395 100.dat
Rate c_raw_size d_raw_trad b_txt_trad a_txt_size
c_raw_size 7855/s -- -87% -88% -96%
d_raw_trad 62625/s 697% -- -4% -70%
b_txt_trad 65166/s 730% 4% -- -68%
a_txt_size 206449/s 2528% 230% 217% --
Now quite why slurping a file in text-mode would be faster (and soo much faster!) than doing so in raw mode leaves me at a total loss for an explaination. Seems that I should reassess what I thought I once knew about Perl IO-layers and performance.
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco.
Rule 1 has a caveat! -- Who broke the cabal?
|