which one is faster?
bruno.42.desthuilliers at websiteburo.invalid
Fri Jan 29 12:00:35 CET 2010
alex23 a écrit :
> On Jan 29, 4:29 pm, "Stephen.Wu" <54wut... at gmail.com> wrote:
>> str.index(targetStr) with exception
>> targetStr in str
>> which is the fastest way to check whether targetStr is in str?
> It's generally a lot quicker to investigate this kind of question
> yourself using the interpreter & the timeit module. You'll need skills
> like these to be able to profile your code to look for actual
> performance bottlenecks, generic advice on the fastest of a set of
> functions will only get you so far.
Indeed. Another point to take into consideration is the _real_ dataset
on which the functions under test will have to work. And possibly the
available resources at runtime. As an example, an iterator-based
solution is likely to be slower than a more straightforward "load
everything in ram" one, but will scale better for large datasets and/or
heavy concurrent access to the system.
More information about the Python-list