[issue17170] string method lookup is too slow
Serhiy Storchaka
report at bugs.python.org
Sat Feb 9 17:51:54 CET 2013
Serhiy Storchaka added the comment:
There are two overheads: an attribute lookup and a function call.
$ ./python -m timeit -s "a = 'hundred'" "'x' in a"
10000000 loops, best of 3: 0.0943 usec per loop
$ ./python -m timeit -s "a = 'hundred'" "a.__contains__('x')"
1000000 loops, best of 3: 0.271 usec per loop
$ ./python -m timeit -s "a = 'hundred'" "a.__contains__"
10000000 loops, best of 3: 0.135 usec per loop
Time of "a.__contains__('x')" is greater than the sum of times of "a.__contains__" and "'x' in a".
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue17170>
_______________________________________
More information about the Python-bugs-list
mailing list