Get time of execution of a block of code in Python 2.7
To get the elapsed time in seconds, you can use timeit.default_timer(): import timeit start_time = timeit.default_timer() # code you want to evaluate elapsed = timeit.default_timer() – start_time timeit.default_timer() is used instead of time.time() or time.clock() because it will choose the timing function that has the higher resolution for any platform.