Use kernprof for script profiling
mainThe kernprof tool allows you to profile Python scripts without modifying the source code. It encapsulates profiling concerns and ensures that script execution remains robust by correctly setting variables like __name__, __file__, and sys.path.
By default, running kernprof script_to_profile.py writes the results to script_to_profile.py.prof.