Skip to main content

A simple way to measure execution time

Project description

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)

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

tictoc-borisgorelik-0.0.1.tar.gz (1.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tictoc_borisgorelik-0.0.1-py3-none-any.whl (2.7 kB view details)

Uploaded Python 3

File details

Details for the file tictoc-borisgorelik-0.0.1.tar.gz.

File metadata

  • Download URL: tictoc-borisgorelik-0.0.1.tar.gz
  • Upload date:
  • Size: 1.8 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.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4

File hashes

Hashes for tictoc-borisgorelik-0.0.1.tar.gz
Algorithm Hash digest
SHA256 06aa47baa69b71aa9372ba349cb85d873ea58c67e35864f56851317bbe9db58a
MD5 670e260d9057eb4ef60388a5fd3d1895
BLAKE2b-256 d6aaa558d0034d51b685a208be57c14df99016dd57e797b11df473d740e3b8b1

See more details on using hashes here.

File details

Details for the file tictoc_borisgorelik-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: tictoc_borisgorelik-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 2.7 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.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4

File hashes

Hashes for tictoc_borisgorelik-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f57de4af248e186efebc7bb0e9d8fee4f6230153fd4c77f437a07eb89280bdb4
MD5 738d36c0f1df489b9934a011b262d3f4
BLAKE2b-256 bc50e51aa8f8c427cc482eccdcb168ab53fc8b21b02e231bf93c4c5f6597679c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page