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

Fredrik Lundh fredrik at pythonware.com
Thu Feb 17 21:21:38 CET 2005

Raymond Hettinger wrote:

> > but refactoring the contains code to use find_internal sounds like a good
> > first step. any takers?
> I'm up for it.


just fyi, unless my benchmark is mistaken, the Unicode implementation has
the same problem:

    str in -> 25.8 µsec per loop
    unicode in -> 26.8 µsec per loop

    str.find() -> 6.73 µsec per loop
    unicode.find() -> 7.24 µsec per loop

oddly enough, if I change the target string so it doesn't contain any partial
matches at all, unicode.find() wins the race:

    str in -> 24.5 µsec per loop
    unicode in -> 24.6 µsec per loop

    str.find() -> 2.86 µsec per loop
    unicode.find() -> 2.16 µsec per loop


More information about the Python-Dev mailing list