Browse files

Fixed timer decorator to handle functions with return values.

  • Loading branch information...
1 parent 9cf4fd6 commit c259fd341c76761d068d1cf6289cdad377861877 @mathuin committed Jan 12, 2012
Showing with 3 additions and 2 deletions.
  1. +3 −2 timer.py
View
5 timer.py
@@ -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.