Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for pnp-timeit, version 0.5.0
Filename, size File type Python version Upload date Hashes
Filename, size pnp_timeit-0.5.0.tar.gz (3.0 kB) File type Source Python version None Upload date Hashes View
Filename, size pnp_timeit-0.5.0-py3-none-any.whl (3.9 kB) File type Wheel Python version py3 Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page