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

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



At 19.45 8/11/97, Mark Manning/Muniz Eng. wrote:
>        if( x eq y ) means "if x is equal to y do z".
>        if( x =~ /y/i ) means "if x contains y do z".
>
>Which is different from what you said (probably because I
>didn't put the "/"'s around y last time).  So what I meant
>was: Is the "eq" faster than the "=~" type of statement?
>Or is this just how you wrote it?

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)

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