Title: 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:

  [EMAIL PROTECTED] ~/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

  [EMAIL PROTECTED] ~/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

  [EMAIL PROTECTED] ~/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/



_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to