Skip to main content

Simple Python code metering library.

Project description

ticktock

Simple Python code metering library.


ticktock is a minimalist library to profile Python code: it periodically displays timing of running code.

Quickstart

First, install ticktock:

pip install py-ticktock

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:

from ticktock import tick

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

This will print:

⏱️ [3-5] 50us count=1

Indicating that lines 3-5 took <50us to run.

You can use ticktock arbitrarily deep inside you Python code and still get meaningful timing information.

When the timer is called multiple times (for example within a loop), measured times will be aggregated and printed periodically (every 2 seconds by default).

As a result, the following code:

from ticktock import tick

for _ in range(1000):
    clock = tick()
    # do some work
    clock.tock()

Will output:

⏱️ [4-6] 50us count=1000

ticktock acts as a context manager to track the timing of a chunk of code:

from ticktock import ticktock

with ticktock():
    time.sleep(1)

Or as a decorator:

from ticktock import ticktock

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

Checkout the documentation for a complete manual!

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.7-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: py_ticktock-0.0.7-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12

File hashes

Hashes for py_ticktock-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 342c81163d5fe782775193fe3a6d436c1c4400faa6af33064f8fb3d5a70bc522
MD5 39947d3353266c88d95ae50c4827feda
BLAKE2b-256 b97f9954bb3579c78831825e2c37adf7fa3f5892871bac77f1c99f91f99938c8

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