import datetime
import cProfile
import pstats
with cProfile.Profile() as pr :
function_to_measure()
# Print stats
stats = pstats.Stats(pr)
stats.sort_stats(pstats.SortKey.TIME)
stats.print_stats()
# Save profiler File
stats.dump_stats(filename="needs_profiling.prof")