On Fri, May 28, 2010 at 14:46, Uri Guttman <u...@stemsystems.com> wrote:
>>>>>> "CO" == Chas Owens <chas.ow...@gmail.com> writes:
>
>  CO> On Fri, May 28, 2010 at 12:44, Uri Guttman <u...@stemsystems.com> wrote:
>
>  >> the negated char class is usually faster than most similar methods. i
>  >> just like it as it says what i really want - a string without any - chars.
>  >> also anchoring helps too in saying this string must be at the beginning
>  >> (he wants the first field).
>
>  CO> Really?  I have never found it so.  Could you explain what is wrong
>  CO> with my benchmark (I get similar results on 5.12)?
>
> on the surface i see nothing wrong with your benchmark. the speed
> differences are relatively minor in all three cases. i distinctly recall
> that negated char classes were faster but it could be for older
> perls. they have continually optimized the regex engine over the years.
snip

Yeah, I vaguely remember people commenting about that back in the 5.6
time frame, but I thought it was bunk then as well.  Any speed
difference tends to be very small (< 10%) in these sorts of cases.  It
is like arguing about which is better

my $x = 'foo';

or

my $x = "foo";

For me, it comes down to size and readability.  I find

my $x = $s =~ /(.*?)-/ ? $1 : "";

easier for my brain to parse than

my $x = $s =~ /^([^-]+)-/ ? $1 : "";

The dual meanings of ^, the possible meanings of - in a character
class, and the repetition of - makes it hard for me to see what it is
looking for.  Of course, my code base is littered with the .*?
construct, so that biases me as well.

-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to