Pathologically Eclectic Rubbish Lister | |
PerlMonks |
Re: Optimizing the bejeezus out of a subby BrowserUk (Patriarch) |
on Jun 24, 2003 at 13:10 UTC ( [id://268483]=note: print w/replies, xml ) | Need Help?? |
The only thing left inside the routine that might be trimable is the inner foreach loop. If the list of aliases generated by @$sec is of any size, then you maybe paying a time penalty for building that list, and might realise some saving by using indexes to iterate over the array for (0..$#{$sec}) { $sec->[$_][_type]... } Also, if _type, _sec & _contents aren't already defined as constants (which are usually UPPERCASE by convention) then making them constants may yield another minor improvement. However, given that each call to the routine is only taking an average of 0.000165 seconds, there isn't exactly a lot of fat to be trimed within the routine. The fact that you are spending 50% of your programs time, a little over 20 seconds in there comes down to the fact that you are calling it 130,000 times. There are a few possibilities that might improve things.
If there is no possibility of reducing the 130,000 calls to the routine, then you might save some by not calling the routine! That is to say, if you inlined the sub at the point(s) of call, you would save the cost of building the stackframe and calling it. Whether this is
Are both questions you must decide given your requirements. How much benefit is realisable will depend on the nature of the code that calls this routine. As an attempt to give some indication, the following (unrepresentative and possibly misrepresentative) benchmark shows that under some circumstances, inlining and/or deferring the printing, can yield some possibly significant benefits.
Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller
In Section
Seekers of Perl Wisdom
|
|