Tiny, dependency-free library for measuring execution time: stopwatch, context manager, and sync/async decorator.
Project description
perfclock
Tiny, dependency-free library for measuring execution time. Built on
time.perf_counter, fully typed, works with sync and async code.
Install
pip install perfclock
Usage
Context manager
from perfclock import Timer
with Timer() as t:
do_work()
print(t.elapsed) # seconds as a float, e.g. 0.03241
print(t) # <Timer stopped, elapsed=32.410 ms>
Decorator (sync or async)
from perfclock import timed
@timed
def crunch():
...
@timed(label="fetch users", output=logger.info)
async def fetch_users():
...
crunch()
# crunch took 1.204 s
The report goes to print by default; pass any callable taking a string
(e.g. logger.info) via output.
Manual stopwatch with laps
t = Timer()
t.start()
step_one(); t.lap()
step_two(); t.lap()
t.stop()
print(t.laps) # [0.51, 1.72] — seconds per step
print(t.elapsed) # total; accumulates across start/stop until reset()
elapsed reads live while the timer is running, and start()/stop()
can be called repeatedly to accumulate time. reset() clears everything.
Human-readable durations
from perfclock import format_duration
format_duration(0.000004) # '4.000 µs'
format_duration(2.5) # '2.500 s'
format_duration(125) # '2 min 5.0 s'
Development
pip install -e ".[dev]"
pytest
License
MIT
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 Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file perfclock-0.1.0.tar.gz.
File metadata
- Download URL: perfclock-0.1.0.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
77af9b60704ad1ed7e76aae4e2f41195aea4171b90a39779da8c84c4bffa285c
|
|
| MD5 |
8182599bf45b5b05b58f6019bf7d6260
|
|
| BLAKE2b-256 |
8d0adf9e7cee12bf5bdb8069806571cc3d6e16eccf8ee0df723b3b397b615f2a
|
File details
Details for the file perfclock-0.1.0-py3-none-any.whl.
File metadata
- Download URL: perfclock-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
95706baf78d35bed745ca825e1e6899ac295f4041c45f22d3637c4fcaf2212a0
|
|
| MD5 |
61b52eb344999643a51b2cc42f4000f1
|
|
| BLAKE2b-256 |
fd04fe3044ef05240e0c6c69336af36e48bc21c415b5210db0dae3f4739983e7
|