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
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.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 16adc82440e09d3991255a02bee1852053a0d1f09801421e1fb2ebf257d9f874 |
|
MD5 | 9b74b1b3bb0d409e94a1ea3cc31d8b75 |
|
BLAKE2b-256 | ca2ca27162c80fe74fa8b39aef7f0f17167f9920e2fa49b463c8a0c8241d2cda |