Measure execution time of small code snippets, write to log
Project description
Project description
Author: PyPnPteam pypnp@protonmail.com
Introduction
Measure execution time of small code snippets, write to log, Plug and Play style
Installation
This package can either be installed using pip or from a tarball using the standard Python distutils.
If installing using pip, you can download latest version from PyPI:
pip install pypnp-timeit
If you are installing from a tarball, run the following command as an administrative user:
python setup.py install
Example & Usage
Example Code 1
copy following code to file: aa.py
import time
from pnp_timeit.pnp_timeit import Pnp_Timeit
@Pnp_Timeit.timeit
def myfunc(arg1, arg2, arg3='hello'):
time.sleep(3)
if __name__ == "__main__":
Pnp_Timeit.enable()
myfunc("a1", "a2", arg3="hello world")
execute file: aa.py
$ python aa.py
{"func": "myfunc", "args": ["a1", "a2"], "kwargs": {"arg3": "hello world"}, "time_cost_seconds": 3.002114}
Example Code 2
copy following code to file: bb.py
import time
import logging
from pnp_timeit.pnp_timeit import Pnp_Timeit
@Pnp_Timeit.timeit
def myfunc(arg1, arg2, arg3='hello'):
time.sleep(3)
if __name__ == "__main__":
logger = logging.getLogger("MYTEST_LOGGER")
ch = logging.StreamHandler()
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
ch.setFormatter(formatter)
logger.addHandler(ch)
logger.setLevel(logging.INFO)
Pnp_Timeit.enable(logger)
myfunc("a1", "a2", arg3="hello world")
execute file: bb.py
$ python bb.py
2020-06-08 16:39:54,151 - MYTEST_LOGGER - INFO - {"func": "myfunc", "args": ["a1", "a2"], "kwargs": {"arg3": "hello world"}, "time_cost_seconds": 3.
01584}
License
MIT license.
If needed for inclusion in other open source projects, I’m glad to relicense this code.
Bugs, Feature Requests & Patches
Security Issues
Contact
PyPnP team pypnp@protonmail.com
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 pnp_timeit-0.5.0.tar.gz.
File metadata
- Download URL: pnp_timeit-0.5.0.tar.gz
- Upload date:
- Size: 3.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a47275f6f7c30efedc172ef2b1ac3273411e1183a461b6794f7943420507befc
|
|
| MD5 |
4396d31dc3e2f02ba3d74d0b48d3b8cf
|
|
| BLAKE2b-256 |
caeb134fd952525d2fa3f75acfbdfbdeec40b82fedb7c05ea99af006f3f237d7
|
File details
Details for the file pnp_timeit-0.5.0-py3-none-any.whl.
File metadata
- Download URL: pnp_timeit-0.5.0-py3-none-any.whl
- Upload date:
- Size: 3.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b3f326ccc20e84afc34ef15427f79b9a8d44edcf606678a26dc630e268824fb1
|
|
| MD5 |
87abfdacbf5ca1cf05b078d072ad3a14
|
|
| BLAKE2b-256 |
ecdfcca771d97aa511f218a47f77c0501cf30826023372759cc4e96c30eb7c5c
|