in reply to Re: shift v. indexing into an array
in thread shift v. indexing into an array
The difference is so small that I'd be more inclined to write this off as statistical noise and/or a CPU-specific characteristic and consider them identical.
For 2) after filtering all printed output it seems declaring my inside loop makes it slightly slower. I would say inside declaration is cleaner and speedup is not worth avoiding it.
Your conclusion is correct and the first sentence is why. In real code, you're going to be doing more in your loop than just declaring a variable, so a 10% difference in the time required to do that declaration will quickly fade into insignificance. Better to keep the declaration close to where the variable is first used to make the source clearer and eliminate any chance of an old value persisting from one iteration into the next.
|
|---|