Skip to main content

A simple function decorator to display its execution time on the console or in the logs.

Project description

executiontime

License: MIT

This module provides a simple function decorator to display its execution time on the console or in the logs.

Installation

Simply install the package with pip:

pip install executiontime

Usage

You simply need to decorate the function and specify a message template.

from executiontime import printexecutiontime

@printexecutiontime("My function's execution took {0}")
def my_function():
    pass

if __name__ == '__main__':
    my_function()

By default, the message will be displayed on the console. But it is also possible to specify a log function, for example.

from logging import info, INFO, basicConfig
from executiontime import printexecutiontime

@printexecutiontime("My function's execution took {0}", display=info)
def my_function():
    pass

if __name__ == '__main__':
    basicConfig(level=INFO)
    my_function()

It is also easy to add a little bit of color:

from executiontime import printexecutiontime, LIGHTBLUE

@printexecutiontime("My function's execution took {0}", color=LIGHTBLUE)
def my_function():
    pass

if __name__ == '__main__':
    my_function()

Project details


Download files

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

Source Distribution

executiontime-0.3.2.tar.gz (2.7 kB view details)

Uploaded Source

Built Distribution

executiontime-0.3.2-py3-none-any.whl (3.2 kB view details)

Uploaded Python 3

File details

Details for the file executiontime-0.3.2.tar.gz.

File metadata

  • Download URL: executiontime-0.3.2.tar.gz
  • Upload date:
  • Size: 2.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.11.7 Linux/5.15.0-92-generic

File hashes

Hashes for executiontime-0.3.2.tar.gz
Algorithm Hash digest
SHA256 fa972264a3bf3ed2b283126aa9bf3008ffe88520ec7bad0e9a8477d20374ffb2
MD5 b0926807c1c5309b6c0f3cab548ed65a
BLAKE2b-256 5e35acc364517cc47b6523a94a7eb8d06f53ec99d5493090cf0e89c656abd7dc

See more details on using hashes here.

File details

Details for the file executiontime-0.3.2-py3-none-any.whl.

File metadata

  • Download URL: executiontime-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 3.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.11.7 Linux/5.15.0-92-generic

File hashes

Hashes for executiontime-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 74fb8b7b6c5bafdcdae3e7ba90d2df1c6fd5eb76daa0bdea724b4b8564b69307
MD5 5dd08f4eff6cb9b5a7e598fd537f62a6
BLAKE2b-256 fb242998ce738a91e991d735831b3aaef3d139daa803958516527bff9102749d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page