John,

Thanks...I was a bit deep in a script trying to figure out why I kept 
getting global key errors (trying to make sure that re.compile and 
import re weren't run but once...doh?) when you responded.

I guess that settles it, then...for this particular instance, '"J" in s' 
is indeed faster than 'r.match("J")'...

Jonathon


John Fouhy wrote:
> On 07/11/06, Jonathon Sisson <[EMAIL PROTECTED]> 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?
> 
> Nope.
> 
> Here's the command again:
> 
> python -m timeit -s 'import re' -s 'r = re.compile("[0-9A-Za-z_.-]")'
> 'r.match("J")'
> 
> -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.
> 
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to