Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import cProfile
- def profile(func):
- """Decorator for run function profile"""
- def wrapper(*args, **kwargs):
- profile_filename = func.__name__ + '.prof'
- profiler = cProfile.Profile()
- result = profiler.runcall(func, *args, **kwargs)
- profiler.dump_stats(profile_filename)
- return result
- return wrapper
- @profile
- def main():
- for i in range(1000000):
- 'aaa'.replace('a','a')
- if __name__ == '__main__':
- main()
- print('ok')
- # read:
- import pstats
- def main():
- p = pstats.Stats(r"C:\Users\User\Desktop\main.prof")
- p.strip_dirs().sort_stats(-1).print_stats()
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement