Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re: Question about regex performance

by choroba (Bishop)
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
لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^2: Question about regex performance
by ted.byers (Monk) on Jun 18, 2014 at 02:16 UTC


    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


      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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1090220]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2017-12-18 00:21 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (466 votes). Check out past polls.