CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions: Re: [anglaissam] Regex benchmark: Edit Log



FishMonger
Veteran / Moderator

Jul 22, 2013, 10:14 AM


Views: 33011
Re: [anglaissam] Regex benchmark

The .* in the first regex tells it to skip over all of the chars and go to the end of the string and then backtrack one char at a time to try and match the pattern at the end.

The second regex first needs to check each char in the string to see if it's a '.' then once that is matched, it checks for each of the next chars one-by-one.

The difference in speed of match becomes greater as the length of the string increases.

The alternation used in each regex is unnecessary and adds inefficiency.

This would be better than the alternation.

Code
$f =~ /.*\.html?$/i;


It would be interesting to benchmark the regex against using index.


(This post was edited by FishMonger on Jul 22, 2013, 10:15 AM)


Edit Log:
Post edited by FishMonger (Veteran) on Jul 22, 2013, 10:15 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives