Perl optimisation help

Lennart Sorensen lsorense-1wCw9BSqJbv44Nm34jS7GywD8/FfD2ys at public.gmane.org
Thu Jun 8 20:38:14 UTC 2006


On Thu, Jun 08, 2006 at 11:07:45PM +0300, Peter wrote:
> I did it with a hash and it is 5 times faster. Still I would like to 
> know what the fastest way to do $var=$var.$add; is.

Perl don't have someting icky like $var .= $more; does it?

The problem is likely that when a string is created a certain amount of
space is allocated, but when adding to it, often you may have to copy
the whole string into a new bigger memory block before adding the new
stuff in.  Not sure how arrays are managed in perl, like do they have to
be copied and reallocated when stuff is added.  Can you predefine how
many entries it should have?  Does join do all the preallocation at
once, or does it just expand to a dumb loop doing the same thing you
were already doing?

How do you do it with a hash?

Len Sorensen
--
The Toronto Linux Users Group.      Meetings: http://tlug.ss.org
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml





More information about the Legacy mailing list