But both "my" and "local" seem to slow down last write operation
Well yeah. my creates a variable that only lasts until the end of the block. (Actually, nothing is not deallocated; it's just marked as empty.) local backs up the variable and restores it at the end of the block.
the 2nd and following assignments seem to take more time than the 1st one. Could that be attributed to some additional overhead?
Accessing lexicals have less overhead, actually. It's a single op, whereas two are needed for package variables. Also, looking up a lexical variable uses an index, while looking up a package variable requires locating a symbol by name.
As you can see, the time needed to print is the same regardless of the type of variable, so this indicates there's something wonky going on here. If you actually performed a proper benchmark, I bet you'll find the difference is smaller than noise. [See dave_the_m's answer]
In reply to Re: "my" slowing down programs?
by ikegami
in thread "my" slowing down programs?
by jf1
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |