Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re^5: In-place bitwise NOT?

by BrowserUk (Pope)
on Jul 28, 2013 at 12:07 UTC ( #1046737=note: print w/replies, xml ) Need Help??

in reply to Re^4: In-place bitwise NOT?
in thread In-place bitwise NOT?

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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1046737]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2018-05-28 01:31 GMT
Find Nodes?
    Voting Booth?