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.
            Asked
            
        
        
            Active
            
        
            Viewed 111 times
        
    0
            
            
         
    
    
        CyberPlayerOne
        
- 3,078
- 5
- 30
- 51
- 
                    This is duplicate question: https://stackoverflow.com/a/62382967/4601890. Also, I recommend [pycharm line profiler plugin](https://plugins.jetbrains.com/plugin/16536-line-profiler) – dankal444 Mar 15 '23 at 14:49
2 Answers
0
            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
 
    
    
        Talha Tayyab
        
- 8,111
- 25
- 27
- 44
-1
            
            
        I've built a small library perf_tool that can perform this kind of benchmarks.
It can be used to profile pieces of codes and also single lines using decorators, here is a simple example:
 from perf_tool import PerfTool
 with PerfTool('test'):
    <The code to be profiled>
Calling it the result is a report showing some metrics like this:
================== PerfTool ==================
task                     |aver(s) |sum(s)  |count   |std     
main                     |   0.065|   0.065|       1|   0.000
  +-test                 |   0.050|   0.005|      10|   0.002
There are also other libraries in that field like linetimer
 
    
    
        Glauco
        
- 1,385
- 2
- 10
- 20
- 
                    fyi link-only answers are not valid answers. Plus the OP's question is off-topic (tool/product/service recommendation) – David Makogon Mar 18 '23 at 15:54
- 
                    Py profiling is a hot topic so far. Not clear to me why it should be off-topic – Glauco Mar 20 '23 at 08:36
