I think this helps us a lot for estimation of how long a program runs in Python. When dealing with a huge amount of data, it takes long time. Showing the running time, started time and end time are useful for logging and improving your program. Certainly there are a few of way to do that. In my view, the following bunch of code is pretty simple and understandable.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
import time from time import gmtime, strftime # *nix system start_time = time.time() # Windows system #start_time = time.clock() print("Started the job on %s" % strftime("%a, %d %b %Y %X +0000", gmtime())) # run all your routines since here main() test_1() finish() # To demonstrate this script, I try to print 100000 integer numbers for i in range(100000): print(i) print("It took %s seconds" % str(time.time() - start_time)) print("Finished the job on %s" % strftime("%a, %d %b %Y %X +0000", gmtime())) |

Compute the running time of your program in Python