Skip to content

A tiny python package which provides you with a decorator to measure execution time of functions

License

Notifications You must be signed in to change notification settings

sid-ant/Execution-Time

Repository files navigation

Execution-Time

Build Status License: MIT

This is a tiny python package which provides you with a decorator to measure execution time (in ms) of functions.

Installation

You should be able to install using pip in the usual ways:

$ pip install Execution-Time

Or just clone this repository and run:

$ python3 setup.py install

Or place the execution_time folder that you downloaded somewhere where it can be accessed by your scripts.

Basic Usage

Import the class ExecutionTime, instantiate it and @obj.timeit decorater becomes available.

from execution_time import ExecutionTime
e = ExecutionTime()

@e.timeit
def foo(arg1):
  do_something(arg1) 
  return 

@e.timeit
def bar():
  hello_world()
  return

foo("dragons")
bar()
bar()
bar()
print(e.logtime_data)

## {'foo': {'times_called': 1, 'total_time': 0.0745, 'average_time': 0.0745}, 'bar': {'times_called': 3, 'total_time': 0.2054, 'average_time': 0.0685}}

logtime_data is a dictionary which contains the data in methodname:time took in ms format.

Additonal Features

  1. Auto-Decorate all functions in a script.

This is a shortcut if you want to auto-deocreate all function. To do so, pass the __name__ attribute to the class instantiation as:

from execution_time import ExecutionTime

def foo():
  do_something()
  return 

def bar():
  hi()

e = ExecutionTime(module_name=__name__)

foo()
bar()

print(e.logdata_time)

Note: The class instantiation must be done after functions have been defined and before they are called. This does limit where this feature can be used and the decorator approach is recommeneded in those scenarios.

  1. Provide console logs.
e = ExecutionTime(console=True)

Output the log time in console as: 2019-07-06 22:07:55,157 [INFO ] Time take by method : foo is 0.12000000000012001 ms

Issues

You can report the bugs at the issue tracker

License

Built with ♥ by Siddhant Chhabra(@siddhant-curious) under MIT License

You can find a copy of the License at https://github.com/siddhant-curious/Execution-Time/blob/master/LICENSE

About

A tiny python package which provides you with a decorator to measure execution time of functions

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published