Measure execution time of any function
Project description
philiprehberger-timerfunc
Measure execution time of any function.
Installation
pip install philiprehberger-timerfunc
Usage
Context Manager
from philiprehberger_timerfunc import timer
with timer() as t:
do_work()
print(f"Took {t.elapsed_ms:.1f}ms")
Decorator
from philiprehberger_timerfunc import timed
@timed
def process_data():
... # logs: "process_data took 42.3ms"
@timed(threshold_ms=100)
def api_call():
... # only logs if slower than 100ms
Benchmark
from philiprehberger_timerfunc import benchmark
result = benchmark(my_function, args=(data,), iterations=1000)
print(f"Mean: {result.mean_ms:.2f}ms, P95: {result.p95_ms:.2f}ms")
print(result) # full stats summary
API
timer()— Context manager returningTimerResult@timed/@timed(threshold_ms=0)— Decorator logging execution timebenchmark(fn, args, kwargs, iterations, warmup)— ReturnsBenchmarkResult
License
MIT
Project details
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 philiprehberger_timerfunc-0.1.3.tar.gz.
File metadata
- Download URL: philiprehberger_timerfunc-0.1.3.tar.gz
- Upload date:
- Size: 4.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bcfe1cbca6e2500f31b7e405f3995c5a60b34aa21176bff8366e1eae3db37330
|
|
| MD5 |
8f2cc69d0efd252f58fba51105a9c00a
|
|
| BLAKE2b-256 |
f40a371934597b94c129cd64a43ea1b3a89ec4f54047da36472b3f39ecbaa829
|
File details
Details for the file philiprehberger_timerfunc-0.1.3-py3-none-any.whl.
File metadata
- Download URL: philiprehberger_timerfunc-0.1.3-py3-none-any.whl
- Upload date:
- Size: 4.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f9b97629299c6f078effd8b202a8efdfed11e9fc60587e59b8dbbc2d835563c3
|
|
| MD5 |
952757167c36882c2af1f8f7da2dd7ac
|
|
| BLAKE2b-256 |
418e9c4bf54fc96be55d5c44e7b0c53903ae017d2ddae0cbf6c51da38a26b96a
|