Skip to main content

TicToc - a simple way to measure execution time

TicToc provides a simple mechanism to measure the wall time (a stopwatch) with a reasonable accuracy.

Crete an object. Run tic() to start the timer, toc() to stop it. Repeated tic-toc's will accumulate the time. The tic-toc pair is useful in interactive environments such as the shell or a notebook. Whenever toc is called, a useful message is automatically printed to stdout. For non-interactive purposes, use start and stop, as they are less verbose.

Following is an example of how to use TicToc:

Usage examples

def leibniz_pi(n):
    ret = 0
    for i in range(n * 1000000):
        ret += ((4.0 * (-1) ** i) / (2 * i + 1))
    return ret

tt_overall = TicToc('overall')  # started  by default
tt_cumulative = TicToc('cumulative', start=False)
for iteration in range(1, 4):
    tt_cumulative.start()
    tt_current = TicToc('current')
    pi = leibniz_pi(iteration)
    tt_current.stop()
    tt_cumulative.stop()
    time.sleep(0.01)  # this inteval will not be accounted for by `tt_cumulative`
    print(
        f'Iteration {iteration}: pi={pi:.9}. '
        f'The computation took {tt_current.running_time():.2f} seconds. '
        f'Running time is {tt_overall.running_time():.2} seconds'
    )
tt_overall.stop()
print(tt_overall)
print(tt_cumulative)

Metadata

Release files for tictoc-borisgorelik 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tictoc-borisgorelik 0.0.3
File Size Uploaded
tictoc-borisgorelik-0.0.3.tar.gz 3.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tictoc-borisgorelik 0.0.3
File Interpreter ABI Platform
tictoc_borisgorelik-0.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 8.0 kB

Release files / tictoc-borisgorelik-0.0.3.tar.gz

Download URL tictoc-borisgorelik-0.0.3.tar.gz
Size 3.1 kB
Tags Source
SHA-256 checksum
How to use checksums
3c251f211ab14512757507d8d9d8414612e11af5c5d9c9989a5345f565291168
BLAKE2b-256 checksum
How to use checksums
3300da02aaac0623c473685381ee7b09d79719617c40a27de10dbdb34aa7a623
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4

Release files / tictoc_borisgorelik-0.0.3-py3-none-any.whl

Download URL tictoc_borisgorelik-0.0.3-py3-none-any.whl
Size 4.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
170a459220b40b895113d375fc5bda25fb7073122313011d5030a0c54ccda808
BLAKE2b-256 checksum
How to use checksums
35a298f3d84feb015ee6e1373831083c09831e6c3255a526ee77d53bf5befcc8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4

Release history Release notifications | RSS feed

This release

0.0.3 This release

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page