Created
December 25, 2015 22:00
-
-
Save webmaster128/f557a5173ab5953f49b9 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 time | |
| class Timer(object): | |
| def __enter__(self): | |
| self.start = time.time() | |
| return self | |
| def __exit__(self, *args): | |
| self.end = time.time() | |
| self.secs = self.end - self.start | |
| self.msecs = round(self.secs * 1000, 2) # millisecs | |
| with Timer() as t: | |
| try: | |
| import cPickle | |
| print("Using import attempt no. 1") | |
| except ImportError: | |
| import pickle | |
| print("Using import attempt no. 2") | |
| print("took %s ms" % t.msecs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment