Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Preprocessor Pranks

by ariels (Curate)
on May 05, 2002 at 13:15 UTC ( [id://164115]=note: print w/replies, xml ) Need Help??


in reply to Preprocessor Pranks

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://164115]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (7)
As of 2024-03-28 09:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found