Asdftimer
asdftimer is a simple Python utility class for measuring elapsed time. It provides an easy-to-use interface for timing code execution, with support for logging and context management.
Features
- Measure elapsed time.
- Log elapsed time using a custom logger or
print(). - Restart the timer at any point.
- Use as a context manager for automatic timing.
Installation
pip install asdftimer
Usage
Basic Usage
from asdftimer import Timer
from time import sleep
timer = Timer()
sleep(2.4)
elapsed_time = timer.stop()
# Output: AsdfTimer took 2.40 seconds
Using a Custom Logger
from asdftimer.timer import Timer
import logging
logger = logging.getLogger(__name__)
timer = Timer(name="LoggedTimer", logger=logger)
# ur code here
timer.stop()
# Output: LoggedTimer took X seconds
Timing a context
from asdftimer.timer import Timer
with Timer(name="ContextTimer") as timer:
pass # ur code here
# Output: ContextTimer took X seconds
API Reference
Timer
__init__(name="AsdfTimer", logger=None, disable_print=False, print_digits=2)
name(str): The name of the timer. Defaults to"AsdfTimer".logger(Logger): A logger instance for logging. Usesprint()ifNone.disable_print(bool): Whether to disable logging/printing the elapsed time. Defaults toFalse.print_digits(int): Number of decimal places to print for elapsed time. Defaults to2.
stop() -> float
Pauses the timer and outputs/returns the elapsed time in seconds.
restart() -> None
Restarts the timer.
__enter__()
Starts the timer when used as a context manager.
__exit__(exc_type, exc_value, traceback)
Stops the timer and outputs the elapsed time when exiting the context.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Contributing
Contributions are welcome! Feel free to open issues or submit pull requests to improve asdftimer.
Author
Developed by Nibs.
Metadata
Release files for asdftimer 0.1.3
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 | |
|---|---|---|---|---|
| asdftimer-0.1.3.tar.gz | 3.5 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| asdftimer-0.1.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.1 kB
Release files / asdftimer-0.1.3.tar.gz
| Download URL | asdftimer-0.1.3.tar.gz |
|---|---|
| Size | 3.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
18ae4df65b669eeed17555882f66077151717764c86c9abed9d114eebad66596
|
|
BLAKE2b-256 checksum How to use checksums |
99cbb70fdcac2b6cb9db56bfc5723e0a542b4133a70b48bd34e7357ee5db3dac
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.2 CPython/3.10.16 Linux/5.15.167.4-microsoft-standard-WSL2
|
Release files / asdftimer-0.1.3-py3-none-any.whl
| Download URL | asdftimer-0.1.3-py3-none-any.whl |
|---|---|
| Size | 4.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
315abfbf271ad371896e59b42c5af3127fc5884ffb53656acf9933f871d0df54
|
|
BLAKE2b-256 checksum How to use checksums |
e1bb7415682d02626b6f1de71bb716a03af24e487d2839601893dcec75b19feb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.2 CPython/3.10.16 Linux/5.15.167.4-microsoft-standard-WSL2
|
Security for asdftimer 0.1.3
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.