Skip to main content

Python package to get an average time of your function

Project description

timetester

Feed it a method and it tells you the average time.

Downloads

pip install timetester
or
python3 -m pip install timetester

Usage

  • Timetester Object
import timetester

def foo(arg):
    print(arg)
    pass

k = timetester.timeTester(foo)
# NOT NECESSARY. Only use if you encountered an error and reloaded the object
k.initialise()
# Run tests
k.runtests(*args,**kwargs)
# Graph the average time taken
k.graph()
# Print a report of how the function did
k.report()
  • Timeout Decorator
import timetester
import time

# Raises error
@timetester.timeout(10)
def foo(bar):
    time.sleep(11)
  • Compare object

The compared functions should have the same intended purpose and the same arguments

import timetester

def foo():
    pass

def bar():
    pass

k= timetester.compare(foo,bar)
# NOT NECESSARY. Only use if you encountered an error and reloaded the function
k.initialise()
# Arguments are passed in here
k.compareFuncs(*args,**kwargs)
# Outputs a graph comparing the time
k.graph()
# Creates a json file consising of the time took for each function to run
k.output_asfile()
# Prints each function on the screen
k.sort()
  • Usage in Real-Time IDE(Terminal)

Joining of functions are generally allowed for timeTester object However, you have to run the actual test function first

import timetester

def foo(args):
    pass

def bar(args):
    pass

# Allowed
timetester.timeTester(foo).initialise().runtests().graph().report()
timetester.timeTester(foo).runtests().graph().report()
timetester.compare(foo,bar).initialise().compareFuncs().graph().sort().output_asfile()
timetester.compare(foo,bar).compareFuncs().output_asfile().graph()

# Not allowed -- You have to run tests first
timetester.timeTester(foo).graph().report()
timetester.timeTester(foo).report()
timetester.compare(foo,bar).initialise().graph().sort().output_asfile()
timetester.compare(foo,bar).graph().sort()

Default options

import timetester
def foo():
    pass

def bar():
    pass

@timetester.timeout(seconds=10,error_message=os.strerror(errno.ETIME))  

k= timetester.timeTester(foo, target=1, print_output=False,runtime=100,maxtime=10,error_time=0,return_type='mean')


# compare object arguments must be methods
# variables can only be changed later
c = timetester.compare(foo,bar)

timeTester object options

  • target(float/int)

    The target time you want the function to be at

import timetester

def foo(arg):
    pass

k = timetester.timeTester(foo,target=0.005)
# or
k.target =0.05

  • runtime(int,float)

How many times the function is ran before taking average

import timetester

def foo(arg):
    pass

k= timetester.timeTester(foo, runtime=100)
# or 
k.runtime = 100

  • print_output(bool)

    disable all print function inside the provided function.

import timetester

def foo(arg):
    print(arg)

k= timetester.timeTester(foo, print_output=False)
# or
k.print_output = False
# Even though the function is intended to print arguments, no output will be printed during run tests
k.runtests('hi','bye')
# After runtests print functions will be normal.
print('hi')

  • maxtime(int/float)

    Maximum time all functions would run

import timetester

def foo(arg):
    sleep(1)

k=timetester.timeTester(foo,maxtime=1)
# or
k.maxtime = 1
k.runtests()
# When the total time is larger than 1 second error will be raised 

  • return_type(choice)

Type of value returned

Types of possible values include:

  1. 'mean'
  2. 'mode'
  3. 'median'
  4. 'harmonicmean'
  5. 'geometricmean'
import timetester

def foo(arg):
    pass

k= timetester.timeTester(foo,return_type='geometricmean')
# or
k.type = 'geometricmean'

timeTester object compatibility

Allows comparision with int, float and decimal.Decimal objects Take this code below:

import timetester
from decimal import Decimal

def foo(args):
    pass

k=timetester.timeTester(foo)
k.runtests()

Lets say the return value of k (k.__repr__()) is 0.1

k==0.1              # True(float)
k<1                 # True(int)
k>=Decimal(0.0001)  # True(Decimal object)
k==0.002            # False(float)
k>1                 # False(int)
k<=Decimal(0.00001) # False(Decimal object)

Compare object options

  • When creating the object, the arguments must all be functions
  • Variables can only be changed later
    So let's say this is the initial code:
import timetester
def foo():
    pass
def bar():
    pass
k=timetester.compare(foo,bar)

  • looptime(int)

Changes how many 'loops' would be ran everytime compareFuncs() would return

# Default
k.looptime
>>2
# Change
k.looptime = 10
setattr(k, 'looptime',10)
# Restart
k.initialise()

  • runtime(int)

Acts like timeTester.runtime option

# Default
k.runtime
>>50
# Change
k.runtime=100
setattr(k, 'looptime',100)
# Restart
k.initialise()

  • errortime(int,float, decimal.Decimal object)

Acts as timetester.error_time option

# Default
k.errortime
>>0 # off
# Change
k.errortime = 0.0001
setattr(k,'errortime',0.0001)
# Restart
k.initialise()

  • print(bool)

Acts as the timetester.print_output option

# Default
k.print
>>False
# Change
k.print = False
setattr(k, 'print',False)
# Restart
k.initialise()
  • meantype(string)

Acts as the timetester.type option

# Default
k.meantype
>>'harmonicmean'
# Change
k.meantype = 'median'
setattr(k, 'meantype','median')
# Restart
k.initialise()

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

timetester-1.1.1.tar.gz (10.0 kB view details)

Uploaded Source

Built Distribution

timetester-1.1.1-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

Details for the file timetester-1.1.1.tar.gz.

File metadata

  • Download URL: timetester-1.1.1.tar.gz
  • Upload date:
  • Size: 10.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.1

File hashes

Hashes for timetester-1.1.1.tar.gz
Algorithm Hash digest
SHA256 728a3f2bef29a972e72e9ab6d470020d913ec34ecb99d8f537ccbecb4eff595f
MD5 125d4464f27ec7d4599f009e5121c961
BLAKE2b-256 f4a2ae051e66d580c9ef3f5b5557ac783714076838ffe83980b26696078eb4a4

See more details on using hashes here.

File details

Details for the file timetester-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: timetester-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 8.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.1

File hashes

Hashes for timetester-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e61cdfca34faff6c578b65018d2cff08daca2424e235db2a22b7050a0d0c3801
MD5 b4bb4baa37f2e13f804c95d0ee0c7508
BLAKE2b-256 e52f126794f1e7c5f84176d5e2591e87708af5232b1f05789b7e0e1a51b85675

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