timeter
timeter is a simple package with a handy set of tools to measure your code execution time.
Having a plain function, a decorator and a context manager, it becomes easier to "timeit" in specific scenarios.
import functools
import logging
import operator
import timeter
logging.basicConfig(level=logging.INFO, # don't forget to setup logging!
format='[{levelname}] {message}',
style='{')
def mult(*numbers: float) -> float:
return functools.reduce(operator.mul, numbers, 1)
@timeter.timeter_decorator(format_spec='Computed factorial of {args} for {time_elapsed} seconds')
def factorial(n: int) -> int:
return int(mult(*(range(2, n + 1))))
def pow(n: float, power: int, /) -> float: # warning: incredibly slow
return mult(*([n] * power))
timeter.timeter(mult, (2, 3, 4),
number=10) # [INFO] Function "mult(2, 3, 4)" executed 10 times for 6.999999999646178e-06 seconds
factorial(6) # [INFO] Computed factorial of (6,) for 2.300000000003688e-06 seconds
n, power = 2, 2 ** 18
with timeter.Timer('math time', verbose=False) as t:
pow(n, power)
print(f'Started at {t.startup_time=}') # Started at t.startup_time=0.0384101
print(f'Finished at {t.end_time=}') # Finished at t.end_time=1.1512166
print(f'{t.time_elapsed} seconds to compute pow({n}, {power})') # 1.1128065 seconds to compute pow(2, 262144)
Install
pip install timeter
Usage
timeter contains three pieces:
timeterfunction to measure execution time for a single function:
timeter.timeter(mult, (2, 3, 4),
number=10) # [INFO] Function "mult(2, 3, 4)" executed 10 times for 6.999999999646178e-06
timeter_decoratorto measure each function's call execution time:
@timeter.timeter_decorator(format_spec='Computed factorial of {args} for {time_elapsed} seconds')
def factorial(n: int) -> int: ...
Timerclass supporting context manager:
with timeter.Timer('math time', verbose=False, logging_level='DEBUG') as t:
pow(n, power)
By default, the result is being print out into sys.stdout. Hence,
you need to set up some basic logging with logging module to see the results.
However, you can set verbose argument to False (except in timeter_decorator)
to manipulate the resulted data by yourself.
You can also change how results get printed by changing format_spec.
See code documentation to see available format values!
P.S.
This library is pretty experimental and may have a questionable API. If you have any suggestions - please leave them in issues.
Metadata
Release files for timeter 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| timeter-1.0.0.tar.gz | 5.3 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| timeter-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.5 kB
Release files / timeter-1.0.0.tar.gz
| Download URL | timeter-1.0.0.tar.gz |
|---|---|
| Size | 5.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0769b45e81273ae44d0ba0c8a458c715a5282f13a78a7b636a613a1f14581dd4
|
|
BLAKE2b-256 checksum How to use checksums |
714e8fb74d7c3e4aea1399b3a9aa3eaf4c0db339b1b2aa740d5b71cb87e154ef
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.0 CPython/3.9.19
|
Release files / timeter-1.0.0-py3-none-any.whl
| Download URL | timeter-1.0.0-py3-none-any.whl |
|---|---|
| Size | 6.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f6da31b86f6004fce516295b88cf5ec431243efa915c5631808aaa5bd0fd5d26
|
|
BLAKE2b-256 checksum How to use checksums |
789ac2f22bd819068bbac0aa14f584530c95504c3bf9c0ffcced97eb88ba271f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.0 CPython/3.9.19
|
Security for timeter 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.