A simple tool for giving immediate visual feedback on the hotspots in your code.
Project description
HeatProfile
HeatProfile
is a Python decorator for profiling the execution time of individual lines within a function. It provides a detailed overview of the function's performance by highlighting each line's cumulative execution time, call count, and average time per call. Additionally, it uses color coding to visually represent the relative time spent on each line, making it easy to spot performance bottlenecks.
Features
- Line-by-Line Profiling: Detailed execution time analysis for each line within the function.
- Color-Coded Output: Visual representation using colors to indicate lines with higher execution times.
- Threshold-Based Coloring: Lines with execution times significantly lower than the maximum are displayed with a white background, ensuring clarity in highlighting performance-critical areas.
- Dynamic Column Widths: Adjusts column widths based on the length of the source code lines, ensuring readability.
Example Output
Installation
To use HeatProfile
, simply copy the heatprofile.py
file to your project directory.
Usage
To profile a function, import heatprofile
from heatprofile.py
and use it as a decorator:
from heatprofile import heatprofile
@heatprofile
def your_function(args):
# function implementation
pass
Run your Python script as usual, and the profiling output will be displayed in the console.
Output Format
- Function Name: Name of the profiled function.
- Function Location: File location of the function.
- Total Function Time: Total execution time of the function.
- Line: Line number in the source code.
- Source Code: The actual source code of the line.
- Cumulative Time(s): Total time spent on this line across all calls.
- Call Count: Number of times this line was executed.
- Time/Call(s): Average execution time per call for this line.
Color Coding
- Red: Lines with higher relative execution times.
- White: Lines with negligible execution times compared to the maximum.
Compatibility
HeatProfile
is compatible with Python 3.x. It has been tested on various platforms with standard Python interpreters.
Contributing
Contributions to HeatProfile
are welcome. Please feel free to submit pull requests, report bugs, or suggest features through the GitHub issue tracker.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for heatprofile-0.0.7-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f9df4f4dc30f2e75db8597d0f26c3417e4c00b5cc22741e5f44e48f70288388f |
|
MD5 | a410dc08d56a7509c4bad7c58c54e70f |
|
BLAKE2b-256 | a59eca42a399b187d429907b8bcc5ae2ea4d76bed3cb02bce2f671f4cdfa0409 |