Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: slow regular expressions

by GrandFather (Saint)
on Aug 08, 2006 at 05:13 UTC ( #566073=note: print w/replies, xml ) Need Help??


in reply to slow regular expressions

That is a veru inefficient version of /a*b/ which is likely to do a vast amount of backtracking!

Update: interesting that if you remove the character class it goes very much faster. It forces backtracking where the non-character class variant manages to fail immediately.

C:\junk>perl noname.pl Compiling REx `a*b' size 6 Got 52 bytes for offset annotations. first at 1 synthetic stclass `ANYOF[ab]'. 1: STAR(4) 2: EXACT <a>(0) 4: EXACT <b>(6) 6: END(0) floating `b' at 0..2147483647 (checking floating) stclass `ANYOF[ab]' +minlen 1 Offsets: [6] 2[1] 1[1] 0[0] 3[1] 0[0] 4[0] Guessing start of match, REx `a*b' against `aaaaaaaaaaaaaaaaaaaaaaaaaa +aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...'... Did not find floating substr `b'... Match rejected by optimizer Hello Freeing REx: `"a*b"' C:\junk>perl noname.pl Compiling REx `a*[b]' size 15 Got 124 bytes for offset annotations. first at 1 synthetic stclass `ANYOF[ab]'. 1: STAR(4) 2: EXACT <a>(0) 4: ANYOF[b](15) 15: END(0) stclass `ANYOF[ab]' minlen 1 Offsets: [15] 2[1] 1[1] 0[0] 3[3] 0[0] 0[0] 0[0] 0[0] 0[0] 0[0] 0[0] 0[0] 0[ +0] 0[0] 6[0] Matching REx `a*[b]' against `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +aaaaaaaaaaaaaaaaaaaa...' Matching stclass `ANYOF[ab]' against `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +aaaaaaaaaaaaaaaaaaaaaaaaaaaaa' Setting an EVAL scope, savestack=3 0 <> <aaaaaaaaaaaa> | 1: STAR EXACT <a> can match 61 times out of 2147483 +647... Setting an EVAL scope, savestack=3 61 <aaaaaaaaaaaa> <> | 4: ANYOF[b] failed... 60 <aaaaaaaaaaa> <a> | 4: ANYOF[b] failed... 59 <aaaaaaaaaa> <aa> | 4: ANYOF[b] failed... 58 <aaaaaaaaa> <aaa> | 4: ANYOF[b] failed... 57 <aaaaaaaa> <aaaa> | 4: ANYOF[b] failed... 56 <aaaaaaa> <aaaaa> | 4: ANYOF[b] failed... 55 <aaaaaa> <aaaaaa> | 4: ANYOF[b] failed... 54 <aaaaa> <aaaaaaa> | 4: ANYOF[b] failed... 53 <aaaaa> <aaaaaaa> | 4: ANYOF[b] failed... 52 <aaaaa> <aaaaaaa> | 4: ANYOF[b] failed... 51 <aaaaa> <aaaaaaa> | 4: ANYOF[b] failed... 50 <aaaaa> <aaaaaaa> | 4: ANYOF[b] failed... 49 <aaaaa> <aaaaaaa> | 4: ANYOF[b] failed... 48 <aaaaa> <aaaaaaa> | 4: ANYOF[b] failed... 47 <aaaaa> <aaaaaaa> | 4: ANYOF[b] failed... 46 <aaaaa> <aaaaaaa> | 4: ANYOF[b] failed... 45 <aaaaa> <aaaaaaa> | 4: ANYOF[b] failed... 44 <aaaaa> <aaaaaaa> | 4: ANYOF[b] failed... 43 <aaaaa> <aaaaaaa> | 4: ANYOF[b] failed... 42 <aaaaa> <aaaaaaa> | 4: ANYOF[b] failed... 41 <aaaaa> <aaaaaaa> | 4: ANYOF[b] failed... 40 <aaaaa> <aaaaaaa> | 4: ANYOF[b] failed... 39 <aaaaa> <aaaaaaa> | 4: ANYOF[b] failed... 38 <aaaaa> <aaaaaaa> | 4: ANYOF[b] failed... 37 <aaaaa> <aaaaaaa> | 4: ANYOF[b] failed... 36 <aaaaa> <aaaaaaa> | 4: ANYOF[b] failed... 35 <aaaaa> <aaaaaaa> | 4: ANYOF[b] failed... 34 <aaaaa> <aaaaaaa> | 4: ANYOF[b] failed... 33 <aaaaa> <aaaaaaa> | 4: ANYOF[b] failed... 32 <aaaaa> <aaaaaaa> | 4: ANYOF[b] failed... 31 <aaaaa> <aaaaaaa> | 4: ANYOF[b] failed... 30 <aaaaa> <aaaaaaa> | 4: ANYOF[b] failed... 29 <aaaaa> <aaaaaaa> | 4: ANYOF[b] failed... 28 <aaaaa> <aaaaaaa> | 4: ANYOF[b] failed... 27 <aaaaa> <aaaaaaa> | 4: ANYOF[b] failed... 26 <aaaaa> <aaaaaaa> | 4: ANYOF[b] failed... 25 <aaaaa> <aaaaaaa> | 4: ANYOF[b] failed... 24 <aaaaa> <aaaaaaa> | 4: ANYOF[b] failed... 23 <aaaaa> <aaaaaaa> | 4: ANYOF[b] failed... 22 <aaaaa> <aaaaaaa> | 4: ANYOF[b] failed... 21 <aaaaa> <aaaaaaa> | 4: ANYOF[b] failed... 20 <aaaaa> <aaaaaaa> | 4: ANYOF[b] failed... 19 <aaaaa> <aaaaaaa> | 4: ANYOF[b] failed... 18 <aaaaa> <aaaaaaa> | 4: ANYOF[b] failed... 17 <aaaaa> <aaaaaaa> | 4: ANYOF[b] failed... 16 <aaaaa> <aaaaaaa> | 4: ANYOF[b] failed... 15 <aaaaa> <aaaaaaa> | 4: ANYOF[b] failed... 14 <aaaaa> <aaaaaaa> | 4: ANYOF[b] failed... 13 <aaaaa> <aaaaaaa> | 4: ANYOF[b] failed... 12 <aaaaa> <aaaaaaa> | 4: ANYOF[b] failed... 11 <aaaaa> <aaaaaaa> | 4: ANYOF[b] failed... 10 <aaaaa> <aaaaaaa> | 4: ANYOF[b] failed... 9 <aaaaa> <aaaaaaa> | 4: ANYOF[b] failed... 8 <aaaaa> <aaaaaaa> | 4: ANYOF[b] failed... 7 <aaaaa> <aaaaaaa> | 4: ANYOF[b] failed... 6 <aaaaa> <aaaaaaa> | 4: ANYOF[b] failed... 5 <aaaaa> <aaaaaaa> | 4: ANYOF[b] failed... 4 <aaaa> <aaaaaaaa> | 4: ANYOF[b] failed... 3 <aaa> <aaaaaaaaa> | 4: ANYOF[b] failed... 2 <aa> <aaaaaaaaaa> | 4: ANYOF[b] failed... 1 <a> <aaaaaaaaaaa> | 4: ANYOF[b] failed... 0 <> <aaaaaaaaaaaa> | 4: ANYOF[b] failed... failed... Setting an EVAL scope, savestack=3 1 <a> <aaaaaaaaaaa> | 1: STAR EXACT <a> can match 60 times out of 2147483 +647... Setting an EVAL scope, savestack=3 ... # much similar stuff omitted EXACT <a> can match 2 times out of 2147483647... Setting an EVAL scope, savestack=3 61 <aaaaaaaaaaaa> <> | 4: ANYOF[b] failed... 60 <aaaaaaaaaaa> <a> | 4: ANYOF[b] failed... 59 <aaaaaaaaaa> <aa> | 4: ANYOF[b] failed... failed... Setting an EVAL scope, savestack=3 60 <aaaaaaaaaaa> <a> | 1: STAR EXACT <a> can match 1 times out of 21474836 +47... Setting an EVAL scope, savestack=3 61 <aaaaaaaaaaaa> <> | 4: ANYOF[b] failed... 60 <aaaaaaaaaaa> <a> | 4: ANYOF[b] failed... failed... Contradicts stclass... Match failed Hello Freeing REx: `"a*[b]"'

DWIM is Perl's answer to Gödel

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2022-05-26 05:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (93 votes). Check out past polls.

    Notices?