ticktock
Simple Python code metering library.
ticktock
is a minimalist library to profile Python code, it displays timing of code snippets periodically.
Installation¶
ticktock
is available in the PyPI repository:
pip install py-ticktock
Quick start¶
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
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