Dive Into Python: call for comments (long)

Andrew Dalke dalke at acm.org
Mon Apr 23 21:43:10 EDT 2001


Steve Lamb wrote:
>    Well, generally {}'s are less efficient but a little easier to read.
[that is, M{0,3} is less efficient than M?M?M?]

I disagree with your statement, but not enough to actually *test*
it to see if I'm right.  I would expect M{0,3} should to be of
comparable performance to (M(MM?)?)? and faster than M?M?M? - in
a simple implementation.

Suppose you have 'X' and match it against M?M?M?X.  The finite
automata will check
  is X equal to M?  No.  Try next node.
  is X equal to M?  No.  Try next node.
  is X equal to M?  No.  Try next node.
  is X equal to X?  Yes. Done.

While in M{0,3} or (M(MM?)?)? it should be
  is X equal to M?  No.  Try next node.
  is X equal to X?  Yes.  Done.

An optimized implementation is allowed to figure out that M?M?M? and
M{0,3} are identical.

                    Andrew
                    dalke at acm.org






More information about the Python-list mailing list