Hi Monks,
Please look at the following short example.
It measures (hopefully...) the time it takes perl to return from the DoIt subroutine. If you scale the value of $max, the time will expand linearily (well, at least on ActivePerl 5.8.8 on XP OS).
Is there any way to reduce this time?
For those that needed more explanations:
This is the problem re-defined:
When calling a sub that uses large data structures (no matter what it does), what general measures one can to reduce the effect of the garbage collection.
For a good answer, see liverpole's below.
#!/usr/bin/perl -w
my $func_done;
my $func_return;
my $max=1000000;
DoIt($max);
$func_return = (times)[0];
printf "Return took %.4f CPU seconds\n", $func_return - $func_done;
sub DoIt{
my $limit=shift;
my $i;
my %myhash;
foreach $i (0..$limit){
$myhash{$i}=1;
}
$func_done = (times)[0];
return;
}