Pete is correct sometimes a complex code may use more CPU than the straight forward match but does depend on whether you can do a match on one line as opposed to multiple. Just as a tip I use <http://www.regexbuddy.com/> http://www.regexbuddy.com/ which is a great tool for regex and has a debug mode that can show exactly how many steps it takes to do a match as in the image I have attached.
From: [email protected] [mailto:[email protected]] On Behalf Of Pete McNeil Sent: Wednesday, August 07, 2013 7:20 PM To: [email protected] Subject: [MBF]Re: CPU Power On 2013-08-07 18:59, David Barker wrote: Almost like Merlin the Six Million Dollar Man, Better..Faster - PCRE is very powerful and you can slim down to even this (just as an example): anywhere 10 pcre (?i:(o?th(is|at|er))) If I might interject,... pcre (Pre Compiled Regular Expressions) The compiler will most likely convert all similar notations of a pattern into the same bit of code... So, it might make more sense to code (?i:(this|that|other)) simply because it is easier to understand and debug. Once it gets compiled it will be optimized to the same code when it meets the metal. The thing to think about when coding with regular expressions for higher performance is the question: how hard does the engine have to work to find the pattern? -- or perhaps another way: how many comparisons does the engine have to make to match the pattern? Optimizing like that usually requires thinking about the problem differently -- which is a good thing. What pattern are you trying to find? Can you limit that to just the parts that really matter? The other side of it -- how the pattern is coded -- is generally well handled by the compiler. You can code the expression a half dozen different ways but if you're trying to describe the same pattern the engine will end up turning it into the same code no matter how you write it down. Hope this helps, _M -- Pete McNeil Chief Scientist ARM Research Labs, LLC www.armresearch.com 866-770-1044 x7010 twitter/codedweller ############################################################# This message is sent to you because you are subscribed to the mailing list <[email protected]>. To unsubscribe, E-mail to: <[email protected]> To switch to the DIGEST mode, E-mail to <[email protected]> To switch to the INDEX mode, E-mail to <[email protected]> Send administrative queries to <[email protected]>
<<image003.jpg>>
