[FEEDBACK] Is this script efficient...is there a better way?
jepler at unpythonic.net
jepler at unpythonic.net
Wed Sep 11 18:46:01 EDT 2002
On Wed, Sep 11, 2002 at 02:53:23PM -0700, Sean 'Shaleh' Perry wrote:
> As a final comment you need to be aware that the more keywords you look for
> the slower this will be. However there is not a way to get around that, it
> is just something to keep in mind.
With a good, simple Regular Expression like
literal1|literal2|...
the time spent searching one string for the compiled RE should be only
proportional to the number of characters in the scanned string (It's just a
big table of state transitions). This is more cycles per character than
a simple comparison, but for some number of comparisons N you start to win.
I hope that Python's implementation of REs has this property, but I'm not
certain. Needing to support things like backrefs and lookahead-assertions
blows this nice simple model of REs out of the water.
Jeff
More information about the Python-list
mailing list