[Python-Dev] string find(substring) vs. substring in string
Batista, Facundo
FBatista at uniFON.com.ar
Wed Feb 16 21:23:59 CET 2005
[Fredrik Lundh]
#- any special reason why "in" is faster if the substring is found, but
#- a lot slower if it's not in there?
Maybe because it stops searching when it finds it?
The time seems to be very dependant of the position of the first match:
fbatista at pytonisa ~/ota> python /usr/local/lib/python2.3/timeit.py -s "s =
'not there'*100" "'not there' in s"
1000000 loops, best of 3: 0.222 usec per loop
fbatista at pytonisa ~/ota> python /usr/local/lib/python2.3/timeit.py -s "s =
'blah blah'*20 + 'not there'*100" "'not there' in s"
100000 loops, best of 3: 5.54 usec per loop
fbatista at pytonisa ~/ota> python /usr/local/lib/python2.3/timeit.py -s "s =
'blah blah'*40 + 'not there'*100" "'not there' in s"
100000 loops, best of 3: 10.8 usec per loop
. Facundo
Bitácora De Vuelo: http://www.taniquetil.com.ar/plog
PyAr - Python Argentina: http://pyar.decode.com.ar/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-dev/attachments/20050216/e799aff5/attachment.html
More information about the Python-Dev
mailing list