Simple performance profiling tool for python
Project description
timebudget
A simple tool to see what's slow in your python program
Trying to figure out where the time's going in your python code? Tired of writing elapsed = time.time() - start_time? Just add a few lines of code to find out.
The simplest way
from timebudget import timebudget
timebudget.report_atexit()
@timebudget
def possibly_slow():
...
@timebudget
def should_be_fast():
...
And now when you run your program, you'll see how much time was spent in each annotated function:
timebudget report...
possibly_slow: 600.62ms for 3 execs
should_be_fast: 300.35ms for 2 execs
More advanced useage
You can wrap specific blocks of code to be measured, and give them a name:
with timebudget("load-file"):
text = open(filename,'rt').readlines()
And you can pick when to print the report instead of doing it atexit:
timebudget.report()
Percent of time in a loop
If you are doing something repeatedly, and want to know the percent of time doing different things, time the loop itself, and pass the name to report:
@timebudget
def outer_loop():
possibly_slow()
should_be_fast()
should_be_fast()
timebudget.report('outer_loop')
Then the report looks like:
timebudget report per outer_loop cycle...
outer_loop: 100.0% 440.79ms/cyc @ 1.0execs/cyc
possibly_slow: 40.9% 180.31ms/cyc @ 3.0execs/cyc
should_be_fast: 13.7% 60.19ms/cyc @ 2.0execs/cyc
Requirements
Needs Python 3.6 or higher. Because type annotations are awesome, and it's 2019, and python 2.7 is on its deathbed.
Tests require pytest.
Inspiration
This tool is inspired by TQDM, the awesome progress bar. TQDM is stupidly simple to add to your code, and just makes it better. I aspire to imitate that.
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 timebudget-0.6.tar.gz.
File metadata
- Download URL: timebudget-0.6.tar.gz
- Upload date:
- Size: 3.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
65875a2cf4e5eb99502458bb85f07129a4e31fdba88b5c243f9aa77a01c38cac
|
|
| MD5 |
f6b09a91e22e7f7e3fa6802c7785822a
|
|
| BLAKE2b-256 |
0dde58d35359d9dd012e18a60a4dcfbef1e9b2fa411ca299b4832732f93fbdc8
|
File details
Details for the file timebudget-0.6-py3-none-any.whl.
File metadata
- Download URL: timebudget-0.6-py3-none-any.whl
- Upload date:
- Size: 8.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d52229131d181b05d912fdca57445737384add0a4278d3a3bea185598e48f791
|
|
| MD5 |
1773178b7279b2784ed45144c57dd1fc
|
|
| BLAKE2b-256 |
035fab621fdc544235500bdbef74acc7930dd9be232fb0c18eb0fb1eabb229a2
|