[DGD] A trivial query about the behaviour of local variables

Michael McKiel crashnbrn71 at yahoo.ca
Sat Apr 24 06:10:23 CEST 2004


I've wondered something along these lines, as I designed my helpd's
find_result_query(). wherein I did something like:

function() {
   <some variables>
   <some code>

   <for loop i> {
      <more variables>
      <some code>

      <for loop j> {
         <more variables>
         <more code>
      }
      <more code>
   }
   return result;
}


But then after figuring out and setting up a test sequence for my last
efficiency question, to find out that a million iterations of the creator()
with 8+ sscanf's ran at 26 seconds, and a million iterations of the
explode/switch&case creator() ran at 30 seconds (which was a suprise to me
that the latter was slower, but insignificantly so for a single call).
    Then the above must result in equally insignificant 'efficiency' results
if the for-loop's local variables were moved to the top of the function, and
thus not restacked/initialized in each loop. So if there is no relevant gain
in code efficiency then the consideration (for non ON^2 operations) should be
in readability. Thus it seems to me local variables to each code section is
cleaner and possibly makes for code that is easier to understand to someone
else - when a few variables are global to the whole function than a dozen or
more heh.

So not really a question, but feel free to correct mis-observations ;)


______________________________________________________________________ 
Post your free ad now! http://personals.yahoo.ca
_________________________________________________________________
List config page:  http://list.imaginary.com/mailman/listinfo/dgd



More information about the DGD mailing list