RE: [Python-Dev] string find(substring) vs. substring in string
[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@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@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@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/
participants (1)
-
Batista, Facundo