Advertisement
DigitalMag

Perfomance

Jun 26th, 2020
1,665
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.69 KB | None | 0 0
  1. import cProfile
  2.  
  3. def profile(func):
  4.     """Decorator for run function profile"""
  5.     def wrapper(*args, **kwargs):
  6.         profile_filename = func.__name__ + '.prof'
  7.         profiler = cProfile.Profile()
  8.         result = profiler.runcall(func, *args, **kwargs)
  9.         profiler.dump_stats(profile_filename)
  10.         return result
  11.     return wrapper
  12.  
  13. @profile
  14. def main():
  15.     for i in range(1000000):
  16.         'aaa'.replace('a','a')
  17.  
  18. if __name__ == '__main__':
  19.     main()
  20.     print('ok')
  21.  
  22.  
  23. # read:
  24.  
  25. import pstats
  26.  
  27. def main():
  28.  
  29.     p = pstats.Stats(r"C:\Users\User\Desktop\main.prof")
  30.     p.strip_dirs().sort_stats(-1).print_stats()
  31.  
  32.  
  33. if __name__ == '__main__':
  34.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement