decorator.py 466 B

12345678910111213141516171819202122232425
  1. #!/usr/bin/env python3
  2. # Copyright 2009-2017 BHG http://bw.org/
  3. import time
  4. def elapsed_time(f):
  5. def wrapper():
  6. t1 = time.time()
  7. f()
  8. t2 = time.time()
  9. print(f'Elapsed time: {(t2 - t1) * 1000} ms')
  10. return wrapper
  11. @elapsed_time
  12. def big_sum():
  13. num_list = []
  14. for num in (range(0, 10000)):
  15. num_list.append(num)
  16. print(f'Big sum: {sum(num_list)}')
  17. def main():
  18. big_sum()
  19. if __name__ == '__main__': main()