My idea of join with list-context read seems to do pretty well (if I read the results correctly).

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.