UPDATE: Err nope. that's per second. Okay, I didn't think it should be fast. I just wanted to see.
use Benchmark qw(cmpthese); cmpthese(50, { while=>sub{ open(SITE, "/usr/share/dict/words"); my $xml; while (<SITE>) { $xml .= $_; } close(SITE); } , slurp=>sub{ open(SITE, "/usr/share/dict/words"); my $xml; local($/); undef $/; $xml = <SITE>; close(SITE); } , join=>sub{ open(SITE, "/usr/share/dict/words"); my $xml = join('', <SITE>); close(SITE); } , sys=>sub{ sysopen(SITE, "/usr/share/dict/words", O_RDONLY); sysread SITE, my $xml, -s SITE; close(SITE); } } ); __END__ Benchmark: timing 50 iterations of join, slurp, sys, while... join: 8 wallclock secs ( 7.99 usr + 0.17 sys = 8.16 CPU) @ 6 +.13/s (n=50) slurp: 0 wallclock secs ( 0.12 usr + 0.14 sys = 0.26 CPU) @ 19 +2.31/s (n=50) (warning: too few iterations for a reliable count) sys: 1 wallclock secs ( 0.01 usr + 0.25 sys = 0.26 CPU) @ 19 +2.31/s (n=50) (warning: too few iterations for a reliable count) while: 5 wallclock secs ( 5.09 usr + 0.12 sys = 5.21 CPU) @ 9 +.60/s (n=50) Rate join while sys slurp join 6.13/s -- -36% -97% -97% while 9.60/s 57% -- -95% -95% sys 192/s 3038% 1904% -- -0% slurp 192/s 3038% 1904% 0% --
--
perl -pe "s/\b;([st])/'\1/mg"
In reply to Re: Reading entire file into scalar: speed differences?
by belg4mit
in thread Reading entire file into scalar: speed differences?
by theguvnor
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |