When I tried your example of changing s/\s+// to s/\s+/ / I still saw the decline in speed in the alias version, albeit more slowly. The ref version went from -40% to -20%.

I saw a similar (but varying) decline for these operations:

$_[0] .= 'abcde'; vs ${ $_[0] } .= 'abcde'; $_[0] = substr( $_[0] , -500); vs ${ $_[0] } = substr(${ $_[0] } , -500);

Presumably this has something to do with writing the value back to an alias?

Update: This is just wrong. When retesting this morning, I realised that, while the differences in speed between the two got closer together as the string grew, they never actually switched. Instead, it was just that the string operation took a proportionally greater part of the time, and thus the cost of using references was relatively less.

The only example I've been able to come up with where the two actually switched is the original version in Pass by ref vs alias : why does scalar size matter?


In reply to Re^2: Pass by ref vs alias : why does scalar size matter? by clinton
in thread Pass by ref vs alias : why does scalar size matter? by clinton

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.