On Fri, 14 Apr 2000, Doug MacEachern wrote:
> > > Orwant and friends in "Algorithms with Perl" page 28 claims the first form
> > > is slower.
>
> faster to *parse*, not faster to *run*. stas, your benchmarks don't test
> parse time.
>
> > It seems that TIMTOWTDI is going to die soon as everybody tells me that I
> > should code as shown in "OO Perl" and ""Algorithms with Perl" :(
> >
> > The books are cool, but why turning them into bibles? The book authors are
> > great, but why rising them into gods?
>
> bibles? gods? i haven't touched either of these books. i'm using '' vs.
> "" because '' is faster for Perl to parse and faster for me to parse.
> i'm thinking about string usage more, rather than just slinging them
> around without a care. i'm trying to avoid interpolation, which turns
> into concatination, which uses more memory and is slower than using a
> list. if i see a '' string, i don't worry, if i see "", i want to look
> close and thing about how expensive it will turn out to be.
>
> there will be exceptions, like "\n", ' define' vs "\ndefine", i do prefer
> the later for readability. in fact, there's plenty of interpolation
> happening in those modules, i very much value readability, and the
> "\n", ' define' did make me cringe a bit. and i will probably change that
> one back.
>
> and, your benchmark of those shows "\ndefine" to be faster, because
> the string being copied is so tiny, it's less expensive than pushing an
> extra item onto the stack. when generating webpages, we generally don't
> deal with such tiny strings, do we?
>
> use Benchmark;
>
> open my $fh, '>', '/dev/null';
>
> my($one, $two, $three, $four) = map { $_ x 1000 } 'a'..'d';
>
> timethese(300_000, {
> concat => sub {
> print $fh "$one$two$three$four";
> },
> list => sub {
> print $fh $one, $two, $three, $four;
> },
> });
>
> Benchmark: timing 300000 iterations of concat, list...
> concat: 12 wallclock secs (10.83 usr + 0.67 sys = 11.50 CPU) @
> 26086.96/s (n=300000)
> list: 9 wallclock secs ( 6.75 usr + 0.59 sys = 7.34 CPU) @
> 40871.93/s (n=300000)
Doug, you are my man :) That's the explanation I was looking for! Thanks a
lot!
P.S. I'm sending a few more benchmarks to the list now :) Apache::Request
rules!!!
______________________________________________________________________
Stas Bekman | JAm_pH -- Just Another mod_perl Hacker
http://stason.org/ | mod_perl Guide http://perl.apache.org/guide
mailto:[EMAIL PROTECTED] | http://perl.org http://stason.org/TULARC/
http://singlesheaven.com| http://perlmonth.com http://sourcegarden.org
----------------------------------------------------------------------