On Feb 15, Russ Foster said:

>> As of Perl 5.6.2 (not released yet), /^(.*?):/ and 
>> /^([^:]*):/ will have the same efficiency (read: speed).  If 
>> you're curious, currently /^.*?:/ and /^[^:]*:/ have the same 
>> speed -- it's the capturing that killed .*?, but I have fixed that.
>
>Just to be clear, it's the capturing (.*?) of the string that suffers the
>most (performance-wise), correct? What do you mean you have it fixed--that
>future versions of Perl don't suffer a hit?

It's not so much the ACTUAL capturing.  Capturing /(.*?):/ and capturing
/([^:]*):/ requires the same effort.  What killed /(.*?):/ is that
normally, Perl's regex engine would optimize /.*?:/ to make .*? jump from
one colon to the next in the string.  However, because of the internal
representation of /(.*?):/, it couldn't do that optimization, and
..*? would move one character at a time, instead of the optimized jump.  I
made it look a little hard for that optimization.

>> And personally, I'd use /([^:]*)/ instead of /^([^:]*):/, 
>> since they match the same thing (assuming there IS a colon in 
>> the string).  Or I'd use /(.*?):/ instead of /^(.*?):/ but whatever.
>
>What's the reason for preferring not to use the '^' ? Is it speed? Or just a
>desire to make a regex a simple as possible?

Personal style.  Regexes are already crufty enough -- if I can reduce the
amount of content in the regex itself, that's good for me.

-- 
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
<stu> what does y/// stand for?  <tenderpuss> why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to