Simple Python code metering library.
Project description
ticktock
Simple Python code metering library.
ticktock
is a minimalist library to profile Python code, it displays timing of code snippets periodically.
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] 1ms count=1
Indicating that lines 3-5 take <1ms to run.
If the timed snippet 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] 1ms count=1000
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 as a decorator:
from ticktock import ticktock
@ticktock
def f():
time.sleep(1)
Checkout the documentation for a complete manual!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Hashes for py_ticktock-0.0.6-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 958b34b6e658cbe0689f05d5aabd9d56c151c0ce7f82c1fba94f6907abc1e7ca |
|
MD5 | 6dc90dac7ed43ef5c0df634a5fd7af7d |
|
BLAKE2b-256 | 94d2714a433dc20381835d0859d455c318901b3de6b1267f49e124ca9c05c7a4 |