Skip to main content

Simple Python code metering library.

Project description

ticktock

Simple Python code metering library.


ticktock is a minimalist library to view Python time performance of Python code.

First, install ticktock:

pip install py-ticktock

Then, anywhere in your code you can use tick to start a clock, and tock to register the end of the snippet you want to time:

t = tick()
# do some work
t.tock()

Even if the code is called many times within a loop, measured times will only periodially (2 seconds by default):

import time
from ticktock import tick

for _ in range(1000):
    t = tick()
    # do some work
    time.sleep(1)
    t.tock()

You can create multiple independent ticks, which will appear as two separate clocks:

for _ in range(1000):
    t = tick()
    # do some work
    time.sleep(1)
    t.tock()

    t = tick()
    # do some other work
    time.sleep(0.5)
    t.tock()

Ticks can share a common starting point:

for k in range(1000):
    t = tick()
    # do some work
    time.sleep(1)
    if k % 2 == 1:
        time.sleep(1)
        t.tock()
    else:
        t.tock()

It is also possible to use ticktock as a context manager to track the timing of a chunk of code:

from ticktock import ticktock

with ticktock():
    time.sleep(1)

Or a decorator, to track the timing of each call to a function:

from ticktock import ticktock

@ticktock
def f():
    time.sleep(1)

f()

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

py_ticktock-0.0.4-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file py_ticktock-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: py_ticktock-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.11

File hashes

Hashes for py_ticktock-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 859d6ab6126aee52e28014395d4224b9f3da5f880249f53455c70f7e3e04eb3b
MD5 b493907b3906fd2649316726aa5e3905
BLAKE2b-256 8f696f30ee1e8742b9e7a4a8c48ae59f9e3afce55c7d3b3f6057b47f312137d4

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