Skip to content

Instantly share code, notes, and snippets.

@MyGodIsHe
Created January 19, 2016 19:02
Show Gist options
  • Save MyGodIsHe/6be3f916715deb07bbdf to your computer and use it in GitHub Desktop.
Save MyGodIsHe/6be3f916715deb07bbdf to your computer and use it in GitHub Desktop.
Processing generators
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