in reply to "my" slowing down programs?
First, a split to a non-lexical array is optimised. Rather than pushing all the split elements onto the stack and then letting the assign operator assign them to the array, split just adds its results directly to the array on the fly, bypassing the assign altogether. This optimisation was only extended to lexical arrays in 5.20.0 5.22.0.
Secondly, when assigning values to an array, any previous contents have to be freed first. This can also take time. By using a 'my' variable, the array is initially empty (which is why the first assign is faster), but you pay for that on scope exit, when the array is emptied while going out of scope (which is why the last print is slower). Essentially you are shifting the cost from the first statement to the last statement.
Dave.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: "my" slowing down programs?
by jf1 (Beadle) on Aug 17, 2015 at 19:21 UTC | |
by dave_the_m (Monsignor) on Aug 17, 2015 at 21:26 UTC | |
by jf1 (Beadle) on Aug 26, 2015 at 22:16 UTC |