be used to profile program' performance--it provides detailed breakdown of call counts and times and so can be used to find performance bottlenecks to give flavor of the timeit modulewe will look at small example suppose we have three functionsfunction_a()function_b()and function_c()all of which perform the same computationbut each using different algorithm if we put all these functions into module (or import them)we can run them using the timeit module to see how they compare here is the code that we would use at the end of the moduleif __name__ ="__main__"repeats for function in ("function_a""function_b""function_c") timeit timer("{ }(xy)format(function)"from __main__ import { }xyformat(function)sec timeit(repeatsrepeats print("{function}({sec fsecformat(**locals())the first argument given to the timeit timer(constructor is the code we want to execute and timein the form of string herethe first time around the loopthe string is "function_a(xy)the second argument is optionalagain it is string to be executedthis time before the code to be timed so as to provide some setup here we have imported from the __main__ ( thismodule the function we want to testplus two variables that are passed as input data ( and )and that are available as global variables in the module we could just as easily have imported the function and data from different module when the timeit timer object' timeit(method is calledit will first execute the constructor' second argument--if there was one--to set things upand then it will execute the constructor' first argument--and time how long the execution takes the timeit timer timeit(method' return value is the time taken in secondsas float by defaultthe timeit(method repeats million times and returns the total seconds for all these executionsbut in this particular case we needed only repeats to give us useful resultsso we specified the repeat count explicitly after timing each function we divide the total by the number of repeats to get its mean (averageexecution time and print the function' name and execution time on the console function_a( sec function_b( sec function_c( sec in this examplefunction_a(is clearly the fastest--at least with the input data that was used in some situations--for examplewhere performance can the cprofile module is usually available for cpython interpretersbut is not always available for others all python libraries should have the pure python profile module which provides the same api as the cprofile moduleand does the same jobonly more slowly