A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2005-February/051594.html below:

[Python-Dev] string find(substring) vs. substring in string

[Python-Dev] string find(substring) vs. substring in string [Python-Dev] string find(substring) vs. substring in stringFredrik Lundh fredrik at pythonware.com
Wed Feb 16 21:08:14 CET 2005
any special reason why "in" is faster if the substring is found, but
a lot slower if it's not in there?

timeit -s "s = 'not there'*100" "s.find('not there') != -1"
1000000 loops, best of 3: 0.749 usec per loop

timeit -s "s = 'not there'*100" "'not there' in s"
10000000 loops, best of 3: 0.122 usec per loop

timeit -s "s = 'not the xyz'*100" "s.find('not there') != -1"
100000 loops, best of 3: 7.03 usec per loop

timeit -s "s = 'not the xyz'*100" "'not there' in s"
10000 loops, best of 3: 25.9 usec per loop

</F>

ps. btw, it's about time we did something about this:

timeit -s "s = 'not the xyz'*100" -s "import re; p = re.compile('not there')" "p.search(s)"
100000 loops, best of 3: 5.72 usec per loop 



More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4