Changeset 601 for branches/decorate/timer.py
- Timestamp:
- 12/03/12 11:57:08 (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/decorate/timer.py
r579 r601 1 1 2 def timed(f): 3 """decorator for timing a function""" 4 def func(*args, **kwds): 5 from time import time 6 t = time() 7 res = f(*args, **kwds) 8 print "Timed: %s" % (time() - t) #XXX: write to a monitor instead ? 9 return res 10 return func 2 def timed(verbose=True): 3 def dec(f): 4 """decorator for timing a function""" 5 from time import time as now 6 __time = [True, None] 7 if not verbose: __time[0] = False 8 def time(stamp=False): 9 if not stamp: return __time[-1] 10 import datetime 11 return datetime.timedelta(seconds=__time[-1]) 12 def __verbose(on=True): 13 __time[0] = bool(on) 14 def func(*args, **kwds): 15 t = now() 16 res = f(*args, **kwds) 17 __time[-1] = now() - t 18 if __time[0]: 19 print "Timed: %s" % __time[-1] 20 return res 21 func.time = time 22 func.verbose = __verbose 23 return func 24 return dec 11 25 12 26
Note: See TracChangeset
for help on using the changeset viewer.