Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Inexplicably slow regex

by Skeeve (Parson)
on Sep 12, 2006 at 18:59 UTC ( [id://572598]=note: print w/replies, xml ) Need Help??


in reply to Inexplicably slow regex

Can't confirm your observations:
use Benchmark qw( cmpthese ); $_ = ' df asdf sadf s f df asdf sadf s f df asdf sadf s f df asdf sadf s f df asdf sadf s f df asdf sadf s f df asdf sadf s f df asdf sadf s f '; our $KEY="df"; cmpthese(-3, { caret => '/^ \s* $KEY /mx', cr => '/\n \s* $KEY /mx', });
Result

           Rate caret    cr
cr    1118569/s    --   -1%
caret 1133366/s    1%    --

s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
+.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e

Replies are listed 'Best First'.
Re^2: Inexplicably slow regex
by Skeeve (Parson) on Sep 12, 2006 at 20:13 UTC
    Even with 0.5MB: Still can't confirm!
    use Benchmark qw( cmpthese ); our $KEY="df"; { local $/; open my $hosts,'/etc/hosts'; $_= <$hosts>; close $hosts; } $_= $_ x (0.5*1024*1024 / length $_); s/$KEY/XX/g; $_.= "\n df "; print length $_,"\n"; cmpthese(-3, { caret => '/^ \s* $KEY /mx', cr => '/\n \s* $KEY /mx', });


    Result

    524114
               Rate    cr caret
    cr    1108181/s    --   -1%
    caret 1118184/s    1%    --

    s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
    +.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e
      It looks like it needs many lines to have a partial match in order to slow things down. Try executing this line before adding the matching line:
      s/^/ /mg;
        I've put the line just before $_.= "\n    df   "; and still no big difference:
        542450
                   Rate    cr caret
        cr    1105787/s    --   -2%
        caret 1131435/s    2%    --

        s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
        +.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e
Re^2: Inexplicably slow regex
by Anonymous Monk on Sep 12, 2006 at 19:47 UTC
    Perhaps the difference is that the text I'm searching (read from a file) is 0.5MB. Also, I only expect one match in the entire file so your example may not show a difference since a match is found immediately.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (4)
As of 2024-03-29 15:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found