Last active
June 9, 2017 21:03
-
-
Save SleepProgger/9ab1fdbe0dc839e82cdd2ba5c17e524b to your computer and use it in GitHub Desktop.
because i am too lazy to write it everytime again
This file contains 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
from time import time as now, sleep | |
class Timer: | |
def __init__(self, msg=None, times=1): | |
self.times = times | |
self.msg = msg | |
def __enter__(self): | |
self.start = now() | |
return self | |
def __exit__(self, *args): | |
needed = now() | |
needed -= self.start | |
if self.msg: | |
print("%s needed %.4f for %i calls. %.2f calls per second. %.7f per call" % ( | |
self.msg, needed, self.times, | |
self.times / max(needed, 0.000000001), | |
needed / self.times, | |
)) | |
self.needed = needed |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment