in reply to "my" slowing down programs?

You're probably seeing the combination of two effects.

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

    Used version is strawberry perl 5.20.2.1 (Windows 7; thus I suspected windows memory management); so I'd expect it to have this optimization built in.

    Your 2nd argument indeed is very intriguing, as this always happens in the last step of the block, no matter whether it's given once or repeated some times.
      Used version is strawberry perl 5.20.2.1
      Correction - the lexical optimisation was introduced in 5.22.0.

      Dave.

        Thanks for the information! Indeed when testing with version 5.22 the timing differences are completely gone.

        P.S.: my trials to install Devel::NYTProf in strawberry perl 5.22.0.1 (Windows 7) failed (due to some failed tests). Did others make the same experience?