A combined time and memory profiler using psutil
Project description
tprofiler
tprofiler is a lightweight Python library that combines time and memory profiling using psutil. It provides both a decorator for profiling individual functions and a command-line tool for profiling entire scripts.
Features
- Combined Time and Memory Profiling: Track execution time and process memory (RSS) before and after function execution.
- Easy-to-Use Decorator:
Simply add
@profileto any function to get detailed profiling output. - Command-Line Tool:
Run any Python script with
tprofilerto obtain an overall profiling summary.
Installation
tprofiler is available on PyPI. Install it using pip:
pip install tprofiler
Usage
1. As a Decorator
Add profiling to any function by importing and applying the decorator:
from tprofiler import profile
@profile(enable_memory=True, enable_time=True, verbose=True)
def my_function(n):
total = sum(range(n))
return total
result = my_function(1000000)
When my_function is called, tprofiler prints the execution time and memory usage details, along with the function's return value if verbose is enabled.
2. As a Command-Line Tool
You can profile an entire script by running:
tprofiler your_script.py [script arguments...]
For example, if you have a script named example.py, run:
tprofiler example.py --option value
This command executes the script and prints an overall profiling summary including total time elapsed and memory consumption.
How It Works
-
Time Profiling:
Uses Python's
timemodule to capture the execution time before and after function calls or script runs. -
Memory Profiling:
Uses
psutilto measure the process's memory usage (RSS) before and after execution.
Contributing
Contributions and improvements are welcome! Feel free to open issues or submit pull requests on GitHub.
License
This project is licensed under the MIT License.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tprofiler-1.0.0.tar.gz.
File metadata
- Download URL: tprofiler-1.0.0.tar.gz
- Upload date:
- Size: 4.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
20f14b0b7b31426159ecafb0184fd57a848c70abb132e5813c24570f05e467c1
|
|
| MD5 |
dc8fddea18ebdd6167ea5ee8ba0a1a10
|
|
| BLAKE2b-256 |
5be4d2209434fd3b5671f5cea35b2daaba89ef7096769e6832134d6a0cf1c2b5
|
File details
Details for the file tprofiler-1.0.0-py3-none-any.whl.
File metadata
- Download URL: tprofiler-1.0.0-py3-none-any.whl
- Upload date:
- Size: 5.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b502e5c1ed729a1c6261fab309dfc145dee148a63efe5409b2e8db39a5be83d8
|
|
| MD5 |
bb6e443c43019bbbd08bfd46f0ed7e44
|
|
| BLAKE2b-256 |
2d1f4a33a85b7e1cf886839812e790419c145d81496d105fb2676d967c191536
|