Last active
December 5, 2017 06:22
-
-
Save priyadhoundiyal/0a2f59bf13f917bbf41a700bd8727a43 to your computer and use it in GitHub Desktop.
Time To Run - simply import timing in python program to get time taken to run it - Source[https://stackoverflow.com/questions/1557571/how-do-i-get-time-of-a-python-programs-execution/1557906#1557906]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import atexit | |
| from time import clock | |
| def secondsToStr(t): | |
| return "%d:%02d:%02d.%03d" % \ | |
| reduce(lambda ll,b : divmod(ll[0],b) + ll[1:], | |
| [(t*1000,),1000,60,60]) | |
| line = "="*40 | |
| def log(s, elapsed=None): | |
| print line | |
| print secondsToStr(clock()), '-', s | |
| if elapsed: | |
| print "Elapsed time:", elapsed | |
| print line | |
| def endlog(): | |
| end = clock() | |
| elapsed = end-start | |
| log("End Program", secondsToStr(elapsed)) | |
| def now(): | |
| return secondsToStr(clock()) | |
| start = clock() | |
| atexit.register(endlog) | |
| log("Start Program") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment