in reply to Re: is 'my' that much faster than 'local'?
in thread is 'my' that much faster than 'local'?
However, I modified twerq's script so that each variable is only declared once. Here is the modified script, which measures time to access or change variables rather than to declare them:
The program now takes 24 seconds when local is used and 18 when my is used. So it appears that local can introduce significant overhead into a program even when the program only declares variables a few times but accesses them over and over.# replace local with "my" local $start_time = time; local $global_variable = "hello!"; for (local $i = 0; $i < 5000000; $i++) { $global_variable = "redefined. . "; } print time - $start_time." seconds\n"; print "$global_variable\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: is 'my' that much faster than 'local'?
by Dominus (Parson) on Mar 27, 2001 at 21:32 UTC |