Created
May 27, 2017 18:26
-
-
Save logarytm/5aa63727451ea53d735d81502c0cf137 to your computer and use it in GitHub Desktop.
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 datetime | |
| import time | |
| class stopwatch(object): | |
| def __init__(self, jobname): | |
| self.jobname = jobname | |
| def __enter__(self): | |
| self.starttime = (datetime.datetime.utcnow() - datetime.datetime(1970, 1, 1)).total_seconds() | |
| def __exit__(self, type, value, traceback): | |
| self.endtime = (datetime.datetime.utcnow() - datetime.datetime(1970, 1, 1)).total_seconds() | |
| print(f'{self.jobname} took {round(self.endtime - self.starttime, 2)}s') | |
| with stopwatch('wow intensive computations'): | |
| time.sleep(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment