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.
In reply to Re: Packages to make perl code go faster?
by hawtin
in thread Packages to make perl code go faster?
by EchoAngel
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |