When to compile regex?

Gerrit Holl gerrit.holl at pobox.com
Mon Feb 14 09:19:19 EST 2000


Ralf Hildebrandt wrote on 950441798:
> On Sun, 13 Feb 2000 07:02:42 -0500, David Shochat <shochat at chelmsford.com> wrote:
> >In section 4.2.3 of the Python Library Reference (1.5.2) it says that
> >using compile is more efficient "when the expresion will be used several
> >times in a single program". I'm trying to figure out the intended
> >meaning of this. Does that mean "executed more than once", or "occurs
> >more than once in the program text"? Specifically, if it only occurs
> >once, but that is in a loop, is there an advantage to compiling before
> >entering the loop?
> 
> Of course! It's a loop, and a loop may be traversed multiple times.

Not necisarryly:

>>> for i in range(0):
...     print "do something"
...

Compiling *in* the loop would be more efficient than compiling outsite
the loop :)

writing-an-empty-program-is-always-the-fastest-solution-ly y'rs - gerrit




More information about the Python-list mailing list