Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

comment on

( [id://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 1046579.pl -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 1046579.pl -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 1046579.pl -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 1046579.pl -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 1046579.pl 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 1046579.pl 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 ./7.pl 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 1046579.pl -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 1046579.pl -N=2**30 Substitution loop at 1046579.pl 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

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2024-04-24 00:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found