[Python-Dev] str.count is slow

Fredrik Lundh fredrik at pythonware.com
Tue Feb 28 01:06:50 CET 2006

(manually cross-posting from comp.lang.python)

Ben Cartwright wrote:

> Your evidence points to some unoptimized code in the underlying C
> implementation of Python.  As such, this should probably go to the
> python-dev list (http://mail.python.org/mailman/listinfo/python-dev).

> This tactic typically avoids most (sometimes all) of the calls to
> memcmp.  Other string search functions, including unicode.count,
> unicode.index, and str.index, use this tactic, which is why you see
> unicode.count performing better than str.count.

it's about time that someone sat down and merged the string and unicode
implementations into a single "stringlib" code base (see the SRE sources for
an efficient way to do this in plain C). [1]

moving to (basic) C++ might also be a good idea (in 3.0, perhaps).  is any-
one still stuck with pure C89 these days ?


1) anyone want me to start working on this ?

More information about the Python-Dev mailing list