I've heard that "my" variables are faster than "local" variables, but I lack the understanding of how things work to assess A) why they're faster, and B) to what degree they'd be faster. My basic question is: is converting a program with all "local" variables in my program to "my" variables going to add any significant performance improvement?
Background: I've been converting a series of 20-150k scripts our company uses to work under use strict to accelerate them with mod_perl. But they use almost all global variables. We've figured out that we can automate 90% of the localizing process with the following TIMTOWTDI hack: create another script to scan through the source code, wrap the whole target script in a subroutine named wrapper which is called once, create declarations for all the formerly implicit global variables making them "local" variables with package name wrapper::variablename. While inelegant, this seemed to be the fastest "time-to-market" approach. But I'm wondering about performance tradeoffs. Given that we have a couple hashes, a dozen arrays and 50-100 scalar variables, I'm trying to figure out if we'd get more than a modest 5-25%-type performance payoff from me spending the time converting these scripts to fully localized my-based ones.
Also, are there other gotchas with this approach that leap out at you?
-
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.
|