Skip to main content

A human friendly time calculator for functions and code blocks

Project description

Time That

made-with-python PyPI version PyPI - Downloads PyPI - Implementation pylint status coverage report pipeline status

A human friendly time calculator for functions and code blocks

Install

pip install timethat

Usage

1) You can use it directly for functions

from timethat import TimedFunction
from time import sleep

@TimedFunction()
def suspicious_function():
    time.sleep(1)

if __name__ == '__main__':
    suspicious_function()

results:

TimeThat -> 1.00 sec. -> suspicious_function

TimedFunction optional parameters:

tag: use tag instead of function name

talk: directly echo or echo in results

For example: @TimedFunction(tag="CustomTag", talk:False)

2) Or you can use it in wherever you want

from timethat import TimeThat
from time import sleep

def suspicious_function():
    TimeThat.start("X1")
    for x in range(100):
    	sleep(1)
    	killer_loop = True    
    TimeThat.stop("X1")

if __name__ == '__main__':
    suspicious_function()

results:

TimeThat -> 3.00 sec. -> X1

Stop optional parameters:

talk: echo directly if true else echo later

3) Or you can use it to measure total calculations

from timethat import TimeThat
from time import sleep

def suspicious_function():
    for x in range(3):
        TimeThat.start("X1")
        sleep(0.3)
        killer_loop = True
        TimeThat.stop("X1",talk=False)

    for x in range(3):
        TimeThat.start("X2")
        sleep(1)
        killer_loop = True
        TimeThat.stop("X2",talk=False)

    TimeThat.summary()

if __name__ == '__main__':
    suspicious_function()

results:

TimeThat -> Total: 0.90 sec, Average: 0.30 sec, Count: 3 -> X1

TimeThat -> Total: 3.00 sec, Average: 1.00 sec, Count: 3 -> X2

Summary optional parameters:

tags: echos all timers if None else only echo given timers

reset: resets all timers

4) And you can use logging instead of printout

import timethat
timethat.TALK_TO_LOG = True
# Now it will print out to logging instead of console

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for timethat, version 1.1.5
Filename, size File type Python version Upload date Hashes
Filename, size timethat-1.1.5.tar.gz (4.5 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page