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 timer

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.1.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.1-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: time_profiler-0.0.1.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.1.tar.gz
Algorithm Hash digest
SHA256 38bb8df9b44ced12984ebcf3c309c0bd007121626978bb800bbd5b8ed388a487
MD5 d5c33111548911b61f4c8b5ffabc5168
BLAKE2b-256 bf62dd1be9ab6e61ef3e64e18776a0f67cd075a1cd88132e2271afc6d0fb6e73

See more details on using hashes here.

File details

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

File metadata

  • Download URL: time_profiler-0.0.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 148e3f45e5dfb44e730e92136763095ca60cacc59b93364f948044b4ddf5ee5e
MD5 0481d8cfa888029ce5205e0be4780748
BLAKE2b-256 164ae4763870b663e75d4e79859d60ff62f11690a4bbbd1d100f1c746faf09a3

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