I am using cProfile try to profile my codes:
cProfile
pr = cProfile.Profile() pr.enable() my_func() # the code I want to profile pr.disable() pr.print_stat
you can use dump_stats. In Python 3.8:
with cProfile.Profile() as pr: my_func() pr.dump_stats('/path/to/filename.prof')