Created
January 19, 2016 19:02
-
-
Save MyGodIsHe/6be3f916715deb07bbdf to your computer and use it in GitHub Desktop.
Processing generators
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
def log(f): | |
def wrap(*args, **kwargs): | |
total = 0 | |
t = time.time() | |
r = f(*args, **kwargs) | |
total += time.time() - t | |
if isinstance(r, types.GeneratorType): | |
try: | |
while 1: | |
t = time.time() | |
yield r.next() | |
total += time.time() - t | |
except StopIteration: | |
pass | |
print total | |
return wrap |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment