Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: the case where regex seems to work slower

by Corion (Patriarch)
on Jul 26, 2017 at 09:32 UTC ( [id://1196090]=note: print w/replies, xml ) Need Help??


in reply to the case where regex seems to work slower

Most likely, the difference comes when one regex engine is backtracking to ultimately fail.

I'm not sure what the exact problem description is, but maybe you can speed things up by making some match fails not greedy or atomic (or both). Maybe the following fails faster:

s/\*/[^$dict]*?/g

Or maybe the following replacement makes things fail faster, as it prevents backtracking over that group if it ever failed.:

s/\*/(?>[^$dict]*)/g

(As a note, your second replacement has no /g flag while the Ruby code uses .gsub in both cases)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2024-04-20 00:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found