84_line_profiler.py 448 B

1234567891011121314151617181920212223242526272829
  1. try:
  2. from line_profiler import LineProfiler
  3. print('[INFO] line_profiler is used')
  4. except ImportError:
  5. exit(0)
  6. def f2(x):
  7. a = 0
  8. for i in range(x):
  9. if i % 5 == 0:
  10. a += i
  11. return a
  12. def f1(x):
  13. res = f2(x)
  14. return res
  15. lp = LineProfiler()
  16. lp.add_function(f2)
  17. # lp.runcall(f2, 1000000)
  18. # lp.print_stats()
  19. ###############################
  20. lp.add_function(f1)
  21. lp.runcall(f1, 1000000)
  22. lp.print_stats()