jf1 has asked for the wisdom of the Perl Monks concerning the following question:
this leads to following timings:while (chomp ($line = <$gsr>)) { my @l1; @l1 = split $tab, $line; @l1 = split $tab, $line; @l1 = split $tab, $line; print(join($tab,@l1[@okc])); print(join($tab,@l1[@okc])); print(join($tab,@l1[@okc])); }
i.e. the 2nd and following assignments seem to take more time than the 1st one. Could that be attributed to some additional overhead? It doesn't happen when omitting the "my" declaration or using "our" instead (see below). This is consistent across runs. If introducing "my" in the middle of a block the effect is the same (see at bottom). Using "local" instead of "my" seems not as expensive. But both "my" and "local" seem to slow down last write operation (is that some artifact? All measurments taken on Windows 7 with outpout redirected to a file).73µs my@l1; 1.71s @l1 = split $tab, $line; 2.40s @l1 = split $tab, $line; 2.33s @l1 = split $tab, $line; 805ms print(join($tab,@l1[@okc])); 798ms print(join($tab,@l1[@okc])); 1.66s print(join($tab,@l1[@okc]));
235µs local @l1; 1.18s @l1 = split $tab, $line; 1.79s @l1 = split $tab, $line; 1.78s @l1 = split $tab, $line; 824ms print(join($tab,@l1[@okc])); 806ms print(join($tab,@l1[@okc])); 1.61s print(join($tab,@l1[@okc])); 92µs our @l1; 1.77s @l1 = split $tab, $line; 1.77s @l1 = split $tab, $line; 1.77s @l1 = split $tab, $line; 829ms print(join($tab,@l1[@okc])); 820ms print(join($tab,@l1[@okc])); 1.03s print(join($tab,@l1[@okc])); #my @l1; 1.78s @l1 = split $tab, $line; 1.77s @l1 = split $tab, $line; 1.77s @l1 = split $tab, $line; 810ms print(join($tab,@l1[@okc])); 805ms print(join($tab,@l1[@okc])); 1.01s print(join($tab,@l1[@okc])); 1.80s @l1 = split $tab, $line; 1.70s my @l1 = split $tab, $line; 2.41s @l1 = split $tab, $line; 807ms print(join($tab,@l1[@okc])); 794ms print(join($tab,@l1[@okc])); 1.65s print(join($tab,@l1[@okc]));
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: "my" slowing down programs?
by dave_the_m (Monsignor) on Aug 17, 2015 at 07:15 UTC | |
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 | |
|
Re: "my" slowing down programs?
by 1nickt (Canon) on Aug 17, 2015 at 06:02 UTC | |
by roboticus (Chancellor) on Aug 17, 2015 at 12:15 UTC | |
by jf1 (Beadle) on Aug 17, 2015 at 08:29 UTC | |
|
Re: "my" slowing down programs?
by BrowserUk (Patriarch) on Aug 17, 2015 at 04:41 UTC | |
by jf1 (Beadle) on Aug 17, 2015 at 07:45 UTC | |
|
Re: "my" slowing down programs?
by ikegami (Patriarch) on Aug 17, 2015 at 12:21 UTC | |
|
Re: "my" slowing down programs?
by soonix (Chancellor) on Aug 17, 2015 at 17:48 UTC | |
|
Re: "my" slowing down programs?
by locked_user sundialsvc4 (Abbot) on Aug 17, 2015 at 12:08 UTC | |
by jf1 (Beadle) on Aug 17, 2015 at 19:07 UTC |