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

2005-02-16 Thread Dennis Allison
Boyer-Moore and variants need a bit of preprocessing on the pattern which makes them great for long patterns but more costly for short ones. On Wed, 16 Feb 2005, Irmen de Jong wrote: > Mike Brown wrote: > > Fredrik Lundh wrote: > > > >>any special reason why "in" is faster if the substring is fo

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

2005-02-16 Thread Irmen de Jong
Mike Brown wrote: Fredrik Lundh wrote: any special reason why "in" is faster if the substring is found, but a lot slower if it's not in there? Just guessing here, but in general I would think that it would stop searching as soon as it found it, whereas until then, it keeps looking, which takes mo

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

2005-02-16 Thread Guido van Rossum
> Assuming stringobject.c:string_contains is the right function, the > code looks like this: > > size = PyString_GET_SIZE(el); > rhs = PyString_AS_STRING(el); > lhs = PyString_AS_STRING(a); > > /* optimize for a single character */ > if (size == 1) >

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

2005-02-16 Thread A.M. Kuchling
On Wed, Feb 16, 2005 at 01:34:16PM -0700, Mike Brown wrote: > time. But I would also hope that it would be smart enough to know that it > doesn't need to look past the 2nd character in 'not the xyz' when it is > searching for 'not there' (due to the lengths of the sequences). Assuming stringobje

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

2005-02-16 Thread Mike Brown
Fredrik Lundh wrote: > any special reason why "in" is faster if the substring is found, but > a lot slower if it's not in there? Just guessing here, but in general I would think that it would stop searching as soon as it found it, whereas until then, it keeps looking, which takes more time. But

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

2005-02-16 Thread Batista, Facundo
Title: RE: [Python-Dev] string find(substring) vs. substring in string [Fredrik Lundh] #- any special reason why "in" is faster if the substring is found, but #- a lot slower if it's not in there? Maybe because it stops searching when it finds it? The time seems to be ve