[Tutor] Amazing power of Regular Expressions...
john at fouhy.net
Tue Nov 7 02:28:11 CET 2006
On 07/11/06, Jonathon Sisson <sisson.j at gmail.com> wrote:
> Just out of curiousity (since I really can't say myself), does the code
> below import re each time it loops? I ran the same commands and saw
> quite similar results (0.176 usec per loop for the first test and 0.993
> usec per loop for the second test), and I was just curious if that
> import (and the re.compile, for that matter) happen with each loop?
Here's the command again:
python -m timeit -s 'import re' -s 'r = re.compile("[0-9A-Za-z_.-]")'
-s means "startup code". So, 'import re' and 're.compile(...)' happen
only once, before the main test starts.
You can read help on timeit by typing 'import timeit; help(timeit)' in
the python console.
More information about the Tutor