AW: Re: Regex help needed...

Richard Gaskin ambassador at fourthworld.com
Sat Jan 30 21:01:33 EST 2016


Paul Dupuis wrote:
 > Wow. I would not have expected such a significant difference. Regex
 > has been around a long time and lots of smart computer science types
 > has spent time coming up with ways to optimize its performance for
 > pattern matching. I assumed (falsely) that regex based filters in LC
 > would be on par or even superior than a custom function using chunks.
 > This leads me to:
 >
 > 1) wondering if LC's hooks to whatever regex tool they are using under
 > the hood is a good as it should be
 > AND
 > 2) planning on rewriting my code to use chunks.

One of the reasons for my seemingly-obsessive benchmarking is to learn 
about what goes on under the hood, and to try to anticipate it when 
choosing among different algos.

LC does such a good job of shielding us from what goes on under the hood 
that we often forget that the relationship between the number of lines 
we write and the number of machine instructions our scripts invoke may 
differ broadly depending on the statement.

My favorite example is: set the scroll of field 1 to 100 -- seems simple 
enough, but having written scrollbar management routines in C back in 
the pre-Cocoa days I learned that a *tremendous* number of low-level 
routines come into play with that one simple line of script.  LC makes 
it easy to take this stuff for granted, since it does all the heavy lifting.

Same with regex.

The beauty of regex is that it's a very generalized solution.  The 
downside of regex is that it's a very generalized solution. ;)

Generalized options can provide convenience, but often at the cost of 
performance.

Purpose-built solutions are usually much faster than generalized ones, 
and with LC's chunk expressions they're fun to write too. :)

There are times when regex will outperform chunk expressions, though, so 
I would caution against rewriting everything.  Benchmarking is the key, 
and some day I will have done enough to be able to come up with a small 
set of useful rules as to when to use chunks and when to use regex.  But 
at the moment, it's half hunch and half benchmarking to confirm the hunch.

-- 
  Richard Gaskin
  Fourth World Systems
  Software Design and Development for the Desktop, Mobile, and the Web
  ____________________________________________________________________
  Ambassador at FourthWorld.com                http://www.FourthWorld.com





More information about the use-livecode mailing list