Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Packages to make perl code go faster?

by hawtin (Prior)
on Feb 15, 2005 at 11:37 UTC ( [id://431117]=note: print w/replies, xml ) Need Help??


in reply to Packages to make perl code go faster?

There are many things that can slow your script down. As others have said usually 5% of the code consumes 90% of the execution time. The trick is to identify where those key routines are and look at ways to speed them up.

I have used tricks like caching results that can have a significant effect:

sub routine1 { my($arg1,$arg2) = @_; ... return $result; }

Is changed to:

{ my %cached_results; sub routine1 { my($arg1,$arg2) = @_; return $cached_results{"$arg1||$arg2"} if(defined $cached_results{"$arg1||$arg2"}); ... $cached_results{"$arg1||$arg2"} = $result; return $result; } sub clear_cache1 { %cached_results = (); } }

I recently had a case where I was using .= to build up a string, converting the routine to pushing strings on to and array and only concatenating at the end of the function reduced memory usage by a factor of 100 and increased speed by a factor of 10 for that one routine.

It is not worth hand coding modules in C until you have tried these types of tricks. The extra maintenance cost will swamp the benefit of speed you get.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://431117]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2024-04-26 03:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found