This seems to be exposing some weird edge cases in perl. I added some extra alias/reference tests like these:
sub by_alias { $_[0] =~ s/\s+//; } sub by_alias2 { for ($_[0]) { s/\s+//; } } sub by_alias3 { ${\$_[0]} =~ s/\s+//; } sub by_ref { ${ $_[0] } =~ s/\s+//; } sub by_ref2 { for (${ $_[0] }) { s/\s+//; } }
I then bumped up the string size so it went in 10k increments rather than 1k, and reduced the loop count. There's a weird effect occuring when the string size switches between 130k -> 140k.
Length of string: 130000 Rate alias ref2 alias2 ref alias3 alias 17544/s -- -67% -67% -68% -68% ref2 52632/s 200% -- -0% -5% -5% alias2 52632/s 200% 0% -- -5% -5% ref 55556/s 217% 6% 6% -- 0% alias3 55556/s 217% 6% 6% 0% -- Length of string: 140000 Rate alias3 alias2 ref2 ref alias alias3 1376/s -- -0% -0% -0% -92% alias2 1377/s 0% -- -0% -0% -92% ref2 1379/s 0% 0% -- -0% -92% ref 1381/s 0% 0% 0% -- -92% alias 16393/s 1092% 1090% 1089% 1087% --
That's just bizarre. It seems for strings < 130k, something strange is occuring with @_ aliasing, and for strings > 130k, for () aliasing and references are going haywire. Very odd indeed. This is debian perl, v5.8.8 built for i486-linux-gnu-thread-multi

In reply to Re: Pass by ref vs alias : why does scalar size matter? by Anonymous Monk
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.