Small tool to track time of Python code blocks.
Project description
about-time
Small tool to track time of Python code blocks.
What does it do?
There are several times we need to instrument and log code execution, to see where complex pipelines are spending the most time in.
A simple start = time.time()
and end = time.time() - start
does not cut it when we want to track several lines at the same time, and/or whole blocks with line granularity.
How to use it?
The tool supports being used like a context manager or a callable handler.
Like this:
from about_time import about_time
with about_time() as t_whole:
with about_time() as t_1:
func_1()
with about_time() as t_2:
func_2('params')
Then, get the timings like this:
print(f'func_1 time: {t_1.duration_human}')
print(f'func_2 time: {t_2.duration_human}')
print(f'total time: {t_whole.duration_human}')
There's also the duration
property, which returns the actual float time in seconds.
You can also use it like:
t = about_time(func_1)
t = about_time(lambda: func_2('params'))
Or you mix and match both:
with about_time() as t_whole:
t_1 = about_time(func_1)
t_2 = about_time(lambda: func_2('params'))
How do I install it?
$ pip install about-time
License
This software is licensed under the MIT License. See the LICENSE file in the top distribution directory for the full license text.
Nice huh?
Thanks for your interest!
I wish you have fun using this tool! :)
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
File details
Details for the file about-time-1.0.0.tar.gz
.
File metadata
- Download URL: about-time-1.0.0.tar.gz
- Upload date:
- Size: 3.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.1.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/3.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a753f93acfe67b280e2a074e24528654b262a58d1bf3ff82c00aa23984490725 |
|
MD5 | 7d3c48558ee15abbb2affcd29db4d19f |
|
BLAKE2b-256 | 1a2c1710aaf95374b9137a0a747bca91d26cfd2c443252820a82f517e65945ec |
Provenance
File details
Details for the file about_time-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: about_time-1.0.0-py3-none-any.whl
- Upload date:
- Size: 3.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.1.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/3.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 62c89a11a6f95e76a086a2affa1733e063a62c8253a7abf514803dab576bfcb5 |
|
MD5 | 8bbfe9bf7d55f496f874d2df81b3159f |
|
BLAKE2b-256 | a6437f16965f10fa3c1fc0c9e1b41e68b2b1f22a15c6c7a2c66c7b0af6c7b441 |