Skip to main content

This project provides a method for determining how long it takes a function to complete its execution.

Project description

time_profiler

This is a Python module for profiling a function's time usage. It's quite useful for determining how long a function will take to execute.

Installation

Install via pip:

pip install time_profiler

Usage

First decorate the function you would like to profile with @timer() and then run that file containing function.

In the following example, we create a simple function called sample_func that allocates lists a, b and then deletes b:

from time_profiler import timer

@timer()
def sample_func():
    a = [1] * (10 ** 6)
    b = [2] * (2 * 10 ** 7)
    del b
    
    return a

if __name__ == '__main__':
    sample_func()

Then execute the code normally. For example, if the file name was example.py, this would result in:

python example.py

Output will be displayed in the terminal as follow:

11-24-2021 10:07:05 AM - timer - INFO - sample_func function ran in 0.10 secs

Parameters

This decorator(@timer()) takes two optional paramaters.

  • file_log: By default is set to false, which means that log file is not created but when set to true there should be a log file named timer.log. Breifly this argument is of boelen type.

  • exp_time: Here you can try to estimate the time to be used. When estimated time is less than actual used time, you get warning log instead of info.

Development

Latest sources are available from github:

https://github.com/harerakalex/timer

Author

Carlos Harerimana

License

MIT

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

time_profiler-0.0.2.tar.gz (3.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

time_profiler-0.0.2-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

Details for the file time_profiler-0.0.2.tar.gz.

File metadata

  • Download URL: time_profiler-0.0.2.tar.gz
  • Upload date:
  • Size: 3.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.11 CPython/3.8.8 Linux/5.11.0-40-generic

File hashes

Hashes for time_profiler-0.0.2.tar.gz
Algorithm Hash digest
SHA256 61431f006461e4a1f6bad10ddc280d829b007931cb87f2d313371518de2838e1
MD5 01ec1efec702a8d12f533669f55adfaa
BLAKE2b-256 c5b53a0d12866126cbfd70bdf39057aa16c4682e51e608a4cbad54bd7e14e53b

See more details on using hashes here.

File details

Details for the file time_profiler-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: time_profiler-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 3.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.11 CPython/3.8.8 Linux/5.11.0-40-generic

File hashes

Hashes for time_profiler-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 19c805cb8283c985f119eba790b72048d915f369d542bf1712971bb4534e0e62
MD5 c4e64579d54ed4a5dd26ec4e5aa8887c
BLAKE2b-256 8649306b14e9a998c31dcdb910da0dd0e0757940926d76e10ec0718ab959f084

See more details on using hashes here.

Supported by

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