in reply to it takes 1-2 seconds to return a string from a subrountine

I've just set this up on my laptop (Celeron 1.3Ghz, 128M ram), and I've got to take the string up to 32 Meg before I start seeing any appreciable effect.

Using the simple expedient of print time, "\n"; for the timer statements, it does confirm that the return is usually starting and finishing within the same second (there's the occasional second discrepancy).

Possible suggestions:

--
Tommy
Too stupid to live.
Too stubborn to die.

Replies are listed 'Best First'.
Re: Re: it takes 1-2 seconds to return a string from a subrountine
by yangtse (Acolyte) on Aug 14, 2002 at 17:43 UTC
    The problem is because I have two heavy processes for loading storable data inside the subrountine. After I moved those two out from the subrountine. The problem brothered me is gone. I guess that it is related to system memory swrap and memory allocation . I am sorry for not providing enough information earlier. Thanks a lot!
    use Storable( retrieve, store) my $string = getString($ARGV[]); ENDING MY TIMER sub getString{ my ($file1, $file2) = @_; my @thisarray = @{retrieve($file1)}; # size ~ 20M my %thishash = %{retrieve($file2)}; # size ~ 5M my $thisString; # here I am doing something # to create a $thisString and its size is less than 100K STARTING MY TIMER return $thisString; }
      You may save alot of memory (and perhaps time) if you can avoid dereferencing the large array and hash refs. Don't dereference and assign them to the array and hash; just leave them as references.