Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Is not $_[0] aliased to the function argument? Why using all those references and dereferences?

Yes, it is aliased. But many people, including myself to some degree, have an aversion to using $_[n] in subroutines and will routinely change them to named vars if the subroutines become more complex than simple one liners.

Hence, when it is important to avoid copying scalar arguments, I prefer to use explicit references rather than implicit aliasing.

Moreover, running your code with N=2**29, I am still getting

I have no explanation for that. This is 5.18, with single and long excluded because they just take too long to run on strings of this length:

C:\test>\perl5.18\bin\perl.exe -N=2**20 Rate classic translate str classic 482/s -- -30% -34% translate 688/s 43% -- -6% str 730/s 52% 6% -- C:\test>\perl5.18\bin\perl.exe -N=2**29 Rate classic str translate classic 0.945/s -- -21% -26% str 1.20/s 27% -- -6% translate 1.27/s 35% 6% -- C:\test>\perl5.18\bin\perl.exe -N=2**30 s/iter classic str translate classic 2.06 -- -19% -26% str 1.68 23% -- -9% translate 1.53 35% 10% -- C:\test>\perl5.18\bin\perl.exe -N=2**31 s/iter str classic translate str 3.97 -- -7% -23% classic 3.69 8% -- -17% translate 3.06 30% 20% --

On my machine tr/// wins hands down for these longer lengths. Which is what I would expect everywhere.

It really surprises me that sub str does as well as it does for as long as it does given this complexity of opcodes from the explicit loop:

Compared the implicit loop of translate:

C:\test>perl -MO=Concise,translate main::translate: 8 <1> leavesub[1 ref] K/REFC,1 ->(end) - <@> lineseq KP ->8 1 <;> nextstate(main 1267 (eval 7):1) v:*,&,{,$ ->2 - <1> null KS/2 ->- 6 <1> rv2sv sKRM/3 ->7 - <@> scope sK ->6 - <0> ex-nextstate v ->2 5 <2> aelem sKM/DREFSV,2 ->6 3 <1> rv2av sKR/3 ->4 2 <#> gv[*_] s ->3 4 <$> const[IV 0] s ->5 7 <"> trans sS/COMPL ->8 syntax OK

And str() is still somewhat light on logic as it currently makes no attempt to deal with misalignments between the string length and the buffer size. I haven't checked to see what effect that has on the length of the string.

Why you would get different results to me for these large size strings; I cannot begin to guess?

With 2**30, it dies with Substitution loop at ./ line 10.

I never saw that because I disabled that test along with single (for taking too long) before the error ever manifest itself.

I can confirm that I also get the error message once the length of the string moves above 2**29:

C:\test>\perl5.18\bin\perl.exe -N=2**29 s/iter long classic str translate long 3.92 -- -74% -78% -81% classic 1.03 282% -- -17% -29% str 0.847 363% 21% -- -14% translate 0.731 436% 40% 16% -- C:\test>\perl5.18\bin\perl.exe -N=2**30 Substitution loop at line 42.

I have no idea what it means?

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to Re^5: In-place bitwise NOT? by BrowserUk
in thread In-place bitwise NOT? by BrowserUk

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others pondering the Monastery: (5)
    As of 2018-06-18 04:56 GMT
    Find Nodes?
      Voting Booth?
      Should cpanminus be part of the standard Perl release?

      Results (108 votes). Check out past polls.