P is for Practical | |
PerlMonks |
Re: Debug code out of production systemsby rcaputo (Chaplain) |
on Jan 25, 2004 at 17:33 UTC ( [id://323984]=note: print w/replies, xml ) | Need Help?? |
A faster way to compile code out of a system is to hide it behind an if(CONSTANT) or unless(CONSTANT), as in The bonus is that you don't introduce more delay in the compile time, which a lot of people apparently dislike. I discovered this in POE, a project where I gained about 20% runtime performance with POE::Preprocessor by replacing small, commonly used functions with macros. A contrived example:
This macro is then used, template-like, in the main body of source as:
Back to compile-time inclusion. POE::Preprocessor uses the common if/elsif/else syntax, tagged with an "# include" marker. That is, if you comment a construct with "# include", it will be evaluated at compile time (using the CONSTANT trick), and the code in the block will be included (or not) depending on the condition's outcome. Problems with macros and source filters in general:
Liz's solution is much smarter than mine. It addresses all these problems. Very nice! -- Rocco Caputo - rcaputo@pobox.com - poe.perl.org
In Section
Meditations
|
|