debuggingtestingand profiling sophisticated testsespecially tests that require setup and teardown (cleanupfor larger projectsusing the unittest module (or third-party unit testing modulekeeps the tests and tested programs and modules separate and is generally more flexible and powerful than using doctests if we hit performance problemsthe cause is most often our own codeand in particular our choice of algorithms and data structuresor some inefficiency in our implementation when faced with such problemsit is always wise to find out exactly where the performance bottleneck israther than to guess and end up spending time optimizing something that doesn' actually improve performance python' timeit module can be used to get raw timings of functions or arbitrary code snippetsand so is particularly useful for comparing alternative function implementations and for in-depth analysisthe cprofile module provides both timing and call count information so that we can identify not only which functions take the most timebut also what functions they in turn call overallpython has excellent support for debuggingtestingand profilingright out of the box howeverespecially for large projectsit is worth considering some of the third-party testing toolssince they may offer more functionality and convenience than the standard library' testing modules provide