Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re^2: Question about regex performance

by ted.byers (Monk)
on Jun 18, 2014 at 02:16 UTC ( #1090237=note: print w/replies, xml ) Need Help??

in reply to Re: Question about regex performance
in thread Question about regex performance


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


Replies are listed 'Best First'.
Re^3: Question about regex performance
by choroba (Bishop) on Jun 18, 2014 at 08:07 UTC
    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://1090237]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (9)
As of 2018-06-25 14:22 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (126 votes). Check out past polls.