On 31.07.2009 18:49, w_a_x_man wrote:
This Ruby code takes 27.5 seconds:
But: One might ask if that is a problem at all, considering that this
Quoting the article:
… it is possible to write so-called “pathological” regular
expressions that Perl matches very very slowly. In contrast,
there are no regular expressions that are pathological for
the Thompson NFA implementation. Seeing the two graphs side
by side prompts the question, “why doesn’t Perl use the
Thompson NFA approach?” It can, it should …
I am not sure as to what exactly your point is. The awk you have been
using might have used a DFA implementation (sed does so AFAIK).
Nowadays most regular expression engines are NFA because of various
reasons (see “Mastering Regular Expressions”).
Usually NFA’s can be tricked into bad runtime performance with
expressions like the one you wrote. I do not consider this a
disadvantage because on the other hand you can optimize your expression
when working with a NFA, for example by deliberately selecting order of
sub expressions in the expression. And, the expression is really
pathologic, i.e. you would not use something like that in practice.
Btw, why don’t you declare the regular expression directly, i.e.
regex = %r(