Inline subs?by Limbic~Region (Chancellor)
|on May 02, 2003 at 00:36 UTC||Need Help??|
Limbic~Region has asked for the
wisdom of the Perl Monks concerning the following question:
Calling a sub to do something takes just a little bit longer (microseconds I have been told) than if you copied and pasted the code in the sub and replaced the sub call with it. The difference is very small and for the sake of maintainability - it is worth the hit.
Beware premature optimization - dragons be hiding ahead.
Now I just happen to have be writing a script that reused the same 5 lines of code several times within a loop, so I made it a sub. This particular loop goes through millions of iterations. Now the difference in run times between using a sub versus copying and pasting the code was under 1 minute, but I wondered if there was a way to get the outcome of copying and pasting, but keep the maintainability of a sub.
I think in Perl 6 (I am oblivious), that you will be able to do just this (if the conditions are right). I asked in the CB and I got various suggestions. I was going to let it drop, but bart prompted me to post here if for no other reason than to have a node to Super Search on when someone else asks the same question.
The suggestions I have heard so far:
If someone knows how to do this without a lot of work - then please divulge. If there is no easy answer, then there is no need to pursue it. If you need that much speed - Perl probably isn't the right solution in the first place ;-)
Cheers - L~R