fork download
  1. from time import time
  2.  
  3.  
  4. class Timer(object):
  5. def __init__(self, func):
  6. """
  7. Decorator for sorting functions
  8. @param func: Function being decorated
  9. @type func: callable
  10. """
  11. self.func = func
  12.  
  13. def __call__(self, *args, **kwargs):
  14. start = time()
  15. ret = self.func(*args, **kwargs)
  16. end = time()
  17. return end - start
  18.  
  19.  
  20. @Timer
  21. def cheese():
  22. for var in xrange(9999999):
  23. continue
  24.  
  25. for var in xrange(10):
  26. print cheese()
Success #stdin #stdout 3.15s 7900KB
stdin
Standard input is empty
stdout
0.314619064331
0.314483880997
0.314293146133
0.312877893448
0.313813924789
0.315447092056
0.314171075821
0.314043998718
0.313999891281
0.314471006393