ExXzile / QuickTimeIt

Function(s) execution timer @decorator with args --> functions wrapper for a quick Python Built-in 'Timeit' modile reports without interrupting or breaking course of a code run.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Function(s) execution timer @decorator with args

functions wrapper for a quick Python Built-in 'Timeit' module reports without interrupting or breaking course of a code run.

installation:

  • save QuickTimeIt.py file in a same directory as your code file
  • or
  • in Python 'lib' installation Path for quick access anytime

making it work:

  • import to your code:

    • from QuickTimeIt import quick_timeit
  • place quick_timeit() as a @decorator above function in your code

    • @quick_timeit()

    • as of this release, only main code funcs can be tested i.e. QuickTimeIt @decorator will fail to execute when attempting to test funcs within classes or funcs nested within other funcs

  • add args to @decorator (Optional)

    • (runs=100000, timing='milli', repeat=3, logfile=True)
  • in order for TimeIt to compute, your func must be 'called' with relevant args/kwargs, if applicable.

  • @quick_timeit() can be placed on multiple funcs at once

  • @quick_timeit() acts as a wrapper and your code/program/script will continue run as intended without it

  • @quick_timeit() will execute every time @decorated function is called:

    • for presentability, avoid adding to frequently called or recurring functions, unless logged to file
    • given it's nature, will execute for every next() or otherwise call from 'generator' type functions
    • as it is using logger mode in a separate thread (if log file not specified), console STDOUT's may overlap with func console outputs, if any

warning:

  • to avoid unpredictable behaviour, avoid using with 'side-effect' functions
    • i.e functions with global declarations.

example:

from QuickTimeIt import quick_timeit

@quick_timeit(runs=100, repeat=3, timing='milli')  # -> QuickTimeIt @decorator with optional args
def beaufort_cipher_mathematical(m, key):
	u = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ_'
	key = (key * (int(len(m) / len(key) + 1)))[0: len(m)]
	answer = [u[(u.index(k) - u.index(m)) % len(u)] for m, k in zip(m, key)]
	
	return ''.join(answer)

optional kwargs:

  • runs= how many runs of a func -> integer
  • repeat= how many times to repeat runs -> integer
  • timing= 'sec', 'milli', 'nano' -> string
    • respectively seconds, milliseconds, nanoseconds
  • logfile= if specified, log will be timestamped and appended to file -> string
    • separate log file will be created for each tested function

defaults:

  • runs=1000
  • repeat=5
  • timing='sec'
  • logfile=None

About

Function(s) execution timer @decorator with args --> functions wrapper for a quick Python Built-in 'Timeit' modile reports without interrupting or breaking course of a code run.


Languages

Language:Python 100.0%