import cProfile


def my_function():
    pass

# Command line interface
# $ python -m cProfile my_script.py

# Programmatically

cProfile.run("my_function()")

# Programmatically, to ﬁle
cProfile.run("my_function()", "my_benchmark.prof")

# Via profiler instance

profiler = cProfile.Profile()
profiler.enable()

my_function()

profiler.disable()
profiler.dump_stats("my_benchmark.prof")
