Function execution timing utilities
Project description
timefunc ⏱️
Function execution timing utilities for Python.
Installation
pip install timefunc
Usage
Decorator
from timefunc import timeit
@timeit
def slow_function():
time.sleep(1)
slow_function()
# Output: slow_function: 1.0012s
Context Manager
from timefunc import Timer
with Timer("database query") as t:
results = db.query()
print(f"Query took {t.elapsed:.2f}s")
Benchmark
from timefunc import benchmark
@benchmark(runs=100, warmup=5)
def function_to_test():
# code to benchmark
pass
function_to_test()
# Output:
# function_to_test:
# Runs: 100
# Mean: 1.23ms
# Median: 1.20ms
# Min: 1.01ms
# Max: 2.45ms
# Std Dev: 0.15ms
Features
- ⏱️ Function timing decorator
- 📊 Benchmarking with statistics
- 🔄 Context manager support
- 📈 Warmup runs for accurate benchmarks
- 📝 Human-readable output
API
@timeit
@timeit(name="custom", print_result=True)
def func(): pass
@benchmark
@benchmark(runs=10, warmup=1, name="custom")
def func(): pass
Timer
with Timer("name", print_result=False) as t:
pass
print(t.elapsed) # seconds as float
print(t.result) # TimingResult object
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
pytimefunc_rj-1.0.0.tar.gz
(3.3 kB
view details)
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 pytimefunc_rj-1.0.0.tar.gz.
File metadata
- Download URL: pytimefunc_rj-1.0.0.tar.gz
- Upload date:
- Size: 3.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6e2afbc03b79c0c1283226a9169a98d8d626d0a96868f99fea297c425f97ce7f
|
|
| MD5 |
a24d69610ebd955df49b4d9b2ffeeb00
|
|
| BLAKE2b-256 |
81b3bdcfdd004562f76e3eb1c9f1611120501b9df56c16fae4087c0355625774
|
File details
Details for the file pytimefunc_rj-1.0.0-py3-none-any.whl.
File metadata
- Download URL: pytimefunc_rj-1.0.0-py3-none-any.whl
- Upload date:
- Size: 3.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
681793ad1cc25011fabbd6fd46cc3feb6e6e02e66b83ad6928224e19c9ac719b
|
|
| MD5 |
e8604b03fb9a9c4e214108a13023d132
|
|
| BLAKE2b-256 |
b044d1ccf2313235cea405c6b437d1772d9f7b79e79b6ceac110f01c67385c69
|