Perl Monk, Perl Meditation | |
PerlMonks |
Re: Preprocessor Pranksby ariels (Curate) |
on May 05, 2002 at 13:15 UTC ( [id://164115]=note: print w/replies, xml ) | Need Help?? |
Well, here's the direct way. (samtregar suggests a more Perlish way, which will do much the same, in a possibly nicer way). I created 2 files, <samp>cond-cpp</samp> and <samp>cond-prl</samp> which contain your codes. Neither ran <samp>-w</samp> or <samp>use strict</samp>; at least the latter will probably reduce the difference in execution time even further (<samp>cond-prl</samp>, however, runs the <samp>-P</samp> switch, for obvious reasons).
We see that <samp>cond-cpp</samp> finishes first, even though it takes more time to do so (to explain this, note that "113.7%" CPU utilization means we've got more than one processor). Load average was kept close to 0 (but this was not enforced in any way). Note also that the preprocessor method requires more system time -- it's starting a new process every time! On a slower uniprocessor machine, we get Here too the CPP method appears to have a slight edge. Explanations? Only thing I can think of is "CPP is faster than Perl at doing this". Doubtless the real <samp>perl</samp> hackers out there can explain this. Importance? Probably almost nil, unless you're starting a great many very short-lived processes.
In Section
Seekers of Perl Wisdom
|
|