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).

<hal4 143 [15:07] ~/Perl/Test >time csh -c 'repeat 500 ./cond-prl >/de +v/null' 0:17.75 elapsed, 14.410+3.200 user+system (99.2%), 0 (0+0) mem (avg. s +hared+unshared stack), 152908 faults, 0/0 I/O <hal4 144 [15:08] ~/Perl/Test >time csh -c 'repeat 500 ./cond-cpp >/de +v/null' 0:16.55 elapsed, 11.630+7.200 user+system (113.7%), 0 (0+0) mem (avg. +shared+unshared stack), 431514 faults, 0/0 I/O
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

<sylvie 113 [16:10] ~/Perl/Test >time csh -c 'repeat 500 ./cond-prl >/ +dev/null' 0:35.42 elapsed, 25.740+6.140 user+system (90.0%), 0 (0+0) mem (avg. s +hared+unshared stack), 154646 faults, 0/0 I/O <sylvie 114 [16:10] ~/Perl/Test >time csh -c 'repeat 500 ./cond-cpp >/ +dev/null' 0:39.19 elapsed, 16.490+18.530 user+system (89.3%), 0 (0+0) mem (avg. +shared+unshared stack), 462331 faults, 0/0 I/O
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 reply to Re: Preprocessor Pranks by ariels
in thread Preprocessor Pranks by cmilfo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.