Skip to content

Commit

Permalink
Fixed timer decorator to handle functions with return values.
Browse files Browse the repository at this point in the history
  • Loading branch information
mathuin committed Jan 12, 2012
1 parent 9cf4fd6 commit c259fd3
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions timer.py
Expand Up @@ -6,9 +6,10 @@ def timer(logger=print):
def decorator(target):
def wrapper(*args, **kwargs):
initial = clock()
target(*args, **kwargs)
retval = target(*args, **kwargs)
msg = "%s finished in %.2f seconds." % (target.__name__, (clock() - initial))
return logger(msg)
logger(msg)
return retval
return wrapper
return decorator

0 comments on commit c259fd3

Please sign in to comment.