[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Bug report on 5.14b1 (fwd)



# The second is significantly slower (though not noticable in most cases).
#  In the first you are using an operator, in the second, a function.
#
# #!perl
# use Benchmark;
# $eq = q{if($^O eq 'MacOS') {$x = 'hey1'}};
# $re = q{if($^O =~ /mac/i ) {$y = 'hey2'}};
# timethese(1000000,{eq=>$eq,re=>$re});
# __END__
#
# Benchmark: timing 1000000 iterations of eq, re...
#         eq: 10 secs (10.92 usr  0.00 sys = 10.92 cpu)
#         re: 19 secs (19.35 usr  0.00 sys = 19.35 cpu)

BTW, before anyone asks, removing the i and changing mac to Mac does speed
things up a *bit*, but it is still significantly slower.  See Jeff Friedl's
Mastering Regular Expressions for more info on optimizing regexs.

Benchmark: timing 1000000 iterations of eq, re...
        eq: 10 secs (10.35 usr  0.00 sys = 10.35 cpu)
        re: 18 secs (17.03 usr  0.00 sys = 17.03 cpu)

Of course, the bottom line is that at this point, we know that for a Mac OS
machine, $^0 will always be 'MacOS'.  So we use the eq operator.  If there
were several ports of perl for Mac OS with different vcalues for $^0, we
would probably ignore the other ones.  But if we didn't, we might then have
to use a regex to parse the value of the variable.

--
Chris Nandor             pudge@pobox.com             http://pudge.net/
%PGPKey=('B76E72AD',[1024,'0824 090B CE73 CA10  1FF7 7F13 8180 B6B6'])



***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch