Search code examples
pythonperformanceprofilingstack-traceexecution-time

Is there a Python library that shows execution time per line?


I have found this library called heartrate which shows how many times each line has been hit. I'm wondering if there is a similar library that can show the execution time of each line? Sometimes a single line can be a bottleneck of a program.

enter image description here


Solution

  • There is a library called pyheat.

    you can install by

    pip install py-heat
    

    and import it using from pyheat import PyHeat

    Pyheat can be used to generate a heatmap of time numbers for each line of code for a Python module. Pass the path of the Python file as a parameter to the PyHeat function.

    ph = PyHeat('merge_sort.py')  # mergesort.py is the example given
    ph.create_heatmap()
    ph.show_heatmap()
    

    Please look into this https://github.com/csurfer/pyheat