Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: declaring lexical variables in shortest scope: performance?

by LanX (Saint)
on Mar 31, 2020 at 11:38 UTC ( [id://11114846]=note: print w/replies, xml ) Need Help??


in reply to declaring lexical variables in shortest scope: performance?

In general:

  • Declaration happens at compile time which should be neglectable.
  • Assignment should be the same. (Or even faster°)
  • The only overhead could be destruction or resetting at end of scope.

Your example with a for loop is a bit unfortunate, because aliasing is complicating things considerably.

Together with various optimizations performance gains or loses should be unpredictable, especially between different versions of Perl.

So benchmark it, I don't think it's worth the effort.

°) BTW, for many years it was commonplace that private variables are faster, not sure if accessing package variables has been optimized in the mean time. ...

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

  • Comment on Re: declaring lexical variables in shortest scope: performance?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2024-04-18 18:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found