Online Pyinstrument Compiler

Profiling Python code with Pyinstrument

Python
from pyinstrument import Profiler
import time

# Start profiling using a context manager
with Profiler() as profiler:

    # Define a series of nested function calls
    def main_function():
        first_function()
        second_function()

    def first_function():
        helper_function()

    def second_function():
        helper_function()

    def helper_function():
        final_function()

    def final_function():
        # Simulate some delay
        time.sleep(0.1)

    # Call the main function
    main_function()

# Print profiling report
profiler.print()