[New-bugs-announce] [issue13134] speed up finding of one-character strings

Antoine Pitrou report at bugs.python.org
Sat Oct 8 22:29:04 CEST 2011

New submission from Antoine Pitrou <pitrou at free.fr>:

In stringlib/fastsearch, instead of using our own loops, we can use memchr() (and, if available, memrchr()) when looking for one-character strings. memchr() is generally quite optimized; on this Linux/glibc machine, I get speedups of 5x-10x:

./python -m timeit -s "large='a'*10000+'b'" "large.find('b')"
-> before: 10.5 usec per loop
-> after: 0.889 usec per loop

./python -m timeit -s "large='b'+'a'*10000" "large.rfind('b')"
-> before: 7.06 usec per loop
-> after: 1.94 usec per loop

components: Interpreter Core
messages: 145186
nosy: haypo, loewis, pitrou
priority: normal
severity: normal
status: open
title: speed up finding of one-character strings
type: performance
versions: Python 3.3

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list