J. Landman Gay wrote:
I had a discussion with Mark Waddingham about this when I was preparing my RevLive session on working with text. There is no absolute "faster" method when comparing regex commands with repeat loops. It all depends on what's in the data, and the engine is optimized differently for each type of search. Data that contains many pattern matches will run faster with a regex command than with a repeat loop; data that contains fewer patterns will run faster in a loop. The best way to determine which method is optimal for any particular stack is to run several tests on representative data and see which is more appropriate.

Well said.

I hope I didn't give the impression that "repeat for each" is always faster than RegEx. The criteria Mark outlined states the case nicely, depending on the data and the operations being performed on it.

My only point was that sometimes writing a few extra lines of code can save clock cycles at runtime. This may be counter-intuitive, since in most cases the more work you can hand off to the engine rather than custom script the better.

But the beauty of RegEx is its seductively concise syntax, which often masks the complexity of what the engine does with it. RegEx is a fairly complex chunk of code under the hood, but if you're doing a very complex task it can be well suited to handling it more efficiently than brute-force alternatives.

For simpler tasks, the engine's "repeat for each" and "put...after" are very fast operations, allowing one to avoid the overhead of the RegEx subsystem for a good many tasks.

The trick is finding the precise dividing line, the code complexity/data complexity/depth ratio that benefits one method over another. If there was a quantified formula for that it would be handy; anyone have a few days available to craft the tests which would give us that ratio? :)

--
 Richard Gaskin
 Managing Editor, revJournal
 _______________________________________________________
 Rev tips, tutorials and more: http://www.revJournal.com
_______________________________________________
use-revolution mailing list
[email protected]
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution

Reply via email to