Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Benchmarks aren't everything

by zby (Vicar)
on Oct 24, 2005 at 12:07 UTC ( #502438=note: print w/ replies, xml ) Need Help??


in reply to Benchmarks aren't everything

It looks like the described technique is an example of Dynamic programming.


Comment on Re: Benchmarks aren't everything
Re^2: Benchmarks aren't everything
by tilly (Archbishop) on Oct 24, 2005 at 12:46 UTC
    Yes, but the implementation is rather more efficient than a naive implementation of dynamic programming would be likely to be.
Re^2: Benchmarks aren't everything
by tilly (Archbishop) on Oct 24, 2005 at 18:45 UTC
    Thinking about it further, I think it is possible to implement this solution with less overhead. If your goal is merely to prevent disasters, then the right optimization is one which is fast in the common case and makes the bad case run, not one which tries to make the bad case fast as well.

    An example of how one might do that is have a flag in every RE node saying whether we are tracking positions in the string that we've been to. If we are, then have a linked list that you scan to find whether your current position has been reached yet. If you're not, then do nothing. Then insert code that once every large number of steps sets this bit in various nodes. (For instance the check might happen when you fail back to a second alternative - do that 10,000 times and then set the bit on your current node.)

    On fast regular expressions all you do is check a flag. On slow ones, you run a lot slower (a linked list is a lot of overhead), but at least you still run.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2014-10-02 03:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    What is your favourite meta-syntactic variable name?














    Results (45 votes), past polls