testingdebuggingprofilingand tuning in this examplethe first argument to timeit(is the code you want to benchmark the second argument is statement that gets executed once in order to set up the execution environment the timeit(function runs the supplied statement one million times and reports the execution time the number of repetitions can be changed by supplying number=count keyword argument to timeit(the timeit module also has function repeat(that can be used to make measurements this function works the same way as timeit(except that it repeats the timing measurement three times and returns list of the results for examplefrom timeit import repeat repeat('math sqrt( )','import math'[ when making performance measurementit is common to refer to the associated speedupwhich usually refers to the original execution time divided by the new execution time for examplein the previous timing measurementsusing sqrt( instead of math sqrt( represents speedup of or about sometimes this gets reported as percentage by saying the speedup is about percent making memory measurements the sys module has function getsizeof(that can be used to investigate the memory footprint (in bytesof individual python objects for exampleimport sys sys getsizeof( sys getsizeof("hello world" sys getsizeof([ , , , ] sum(sys getsizeof(xfor in [ , , , ] for containers such as liststuplesand dictionariesthe size that gets reported is just for the container object itselfnot the cumulative size of all objects contained inside of it for instancein the previous examplethe reported size of the list [ , , , is actually smaller than the space required for four integers (which are bytes eachthis is because the contents of the list are not included in the total you can use sum(as shown here to calculate the total size of the list contents be aware that the getsizeof(function is only going to give you rough idea of overall memory use for various objects internallythe interpreter aggressively shares objects via reference counting so the actual memory consumed by an object might be far less than you first imagine alsogiven that extensions to python can allocate memory outside of the interpreterit may be difficult to precisely get measurement of overall memory use thusa secondary technique for measuring the actual memory footprint is to inspect your running program from an operating system process viewer or task manager franklya better way to get handle on memory use may be to sit down and be analytical about it if you know your program is going to allocate various kinds of data structures and you know what kinds of data will be stored in those structures (that isintsfloatsstringsand so on)you can use the results of the getsizeof(function to lib fl ff