https://github.com/felix-andreas/pyprofilers
A simple wrapper library for various Python Profilers.
https://github.com/felix-andreas/pyprofilers
python python-profilers
Last synced: 5 months ago
JSON representation
A simple wrapper library for various Python Profilers.
- Host: GitHub
- URL: https://github.com/felix-andreas/pyprofilers
- Owner: felix-andreas
- License: gpl-3.0
- Created: 2019-09-26T15:59:23.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-09-24T16:54:54.000Z (over 5 years ago)
- Last Synced: 2025-03-14T04:46:39.264Z (10 months ago)
- Topics: python, python-profilers
- Language: Python
- Homepage:
- Size: 33.2 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PyProfilers
PyProfilers is collection of wrapper functions for various Python profilers which aims to make profiling more convenient.
## Installing
Install and update using pip:
```sh
pip install -U pyprofilers
```
## Usage
### Import PyProfilers
```python
import pyprofilers as pp
```
### Profile with [cProfile](https://docs.python.org/3/library/profile.html#module-cProfile)
Use the standard Python [cProfile](https://docs.python.org/3/library/profile.html#module-cProfile) to list
the cumulative time spent in the function `func` and all its subfunctions:
```python
@pp.profile(sort_by='cumulative', out_lines=30)
def func():
...
```
- `sort_by` can be used to sort the results according to the supplied criteria. All criterias can be found [here.](https://docs.python.org/2/library/profile.html#pstats.Stats.sort_stats)
- `out_lines` controls the number of lines in results. Use `None` or ommit the arugment to show all.
### Profile with [line_profiler](https://github.com/pyutils/line_profiler)
Use the [line_profiler](https://github.com/pyutils/line_profiler) to list time spent within each line of `func`:
```python
@pp.profile_by_line(exit=1)
def func():
...
```
Set `exit` to `True` to stop the execution after the first call to `func` returns. This is useful if `func` is called multiple times to
avoid the repeated output of the profiler statistics.
### Simple Timer
To just time the execution of a function use the `simple_timer` decoration:
```python
@pp.simple_timer(num=1)
def func():
...
```
The `num` argument can be used to specify how often the function should be executed.
## License
[GNU General Public License v3.0](https://github.com/andreasfelix/pyprofilers/blob/master/LICENSE)