Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Question about regex performance

by choroba (Abbot)
on Jun 17, 2014 at 22:20 UTC ( #1090220=note: print w/ replies, xml ) Need Help??


in reply to Question about regex performance

regex_or seems wrong. It uses space, while the other regexes use \s. It also groups for no reason, and || contains an empty regex in the middle. I'd change it to

s/^\s+|\s+$//g
لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ


Comment on Re: Question about regex performance
Select or Download Code
Re^2: Question about regex performance
by ted.byers (Scribe) on Jun 18, 2014 at 02:16 UTC

    Thanks.

    Define 'wrong', please. Is it wrong if it gives the right answer? Can you provide a test case that makes it fail? I do like test driven development since the tests define what is right or wrong (as long as they are carefully constructed, and defined by the functional requirements). My usual approach is to make the code right, first, as defined by the suite of unit and integration tests, and then make it fast (hence my search for alternate ways of doing the same thing). In some respects, though, regex_or is one I found, and it remains one I am not entirely sure I understand how or why it works. Regex are not my forte: I am more a quant, working with numeric methods: when working up regular expressions, I still have to have a reference for them open while I try to construct them.

    I do like the approach you say you'd replace regex_or with, but that is one_liner. And that is still about 10% slower than both replace and double_plus, as is double_star. Do you have any thoughts as to why one_liner and double_star are about the same speed, why replace and double_plus are about the same speed, and why the first two are about 10% slower than the latter two? More importantly, is there a way to have code that verifies any conjecture as to why, or does such an explanation have to rest on arguments about how regex work?

    Thanks again

    Ted

      OK, "wrong" was probably a too strong word (I'm not a native speaker of English). But compare the following two expressions, both being "right" from the test driven perspective:
      # 1 $x = 'a' . $y . $z->[1]; # 2 $x = join q(), scalar(chr 97), $y, (@$z)[1], '';
      لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (6)
As of 2014-08-29 23:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (289 votes), past polls