Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^2: Pass by ref vs alias : why does scalar size matter?

by clinton (Priest)
on May 01, 2008 at 22:22 UTC ( #684044=note: print w/ replies, xml ) Need Help??


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

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?


Comment on Re^2: Pass by ref vs alias : why does scalar size matter?
Select or Download Code
Re^3: Pass by ref vs alias : why does scalar size matter?
by mscharrer (Hermit) on May 01, 2008 at 22:39 UTC
    Presumably this has something to do with writing the value back to an alias?
    Good idea. I was testing an operation which doesn't change the variable, m/\s+/, which results in alias only about 2% faster than ref, independent from length.

    One thing I liked to test was the influence the change of the string length by the operation has. When I changed s/\s+// to s/\s+//g the difference is again about 2% in favor of alias, otherwise it's about the same for s/\s/_/g which doesn't change the length.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://684044]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (16)
As of 2014-10-23 13:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (125 votes), past polls