in reply to Re^2: Array How to/Performance
in thread Array How to/Performance: mass initialization or update using array slice

But... isn't it good to know the fastest way for future reference? And... isn't tuning a good pedalogical tool for understanding Perl internals?

-Tats

Replies are listed 'Best First'.
Re^4: Array How to/Performance
by Aristotle (Chancellor) on Jun 21, 2003 at 19:17 UTC

    "Pedalogical"? If you mean pathological - then yes. :) If you mean pegagogical, then so-so with a grain of maybe.

    This being as "micro" an optimization as it is, it is not likely you will be able to say it will be faster than something else in any particular case. If you can do more work than initializing the array in a loop, then using the slice method to fill it up front may possibly end up being slightly slower, f.ex. In any case this is not going to make a significant difference. The bottom line is that either way you turn it, you'll have to benchmark it for your data and your algorithm.

    Makeshifts last the longest.

      Hmm... that was a dumb typo -- should be pedagogic. Just for grins, here goes:

      • Pedagogic = about teaching
      • Pedologic = about children
      • Pedologic = study of soil (alternate)

      Anyways, I think BrowserUk's answer and the OP's subsequent benchmark have value in understanding both the internals and what kind of things might be good suspects for optimization in other programs. Personally I wouldn't have known this to be such a drastically micro-optimization without doing a benchmark.