Todd's Timer
A versatile and easy-to-use Python timer utility for measuring code execution time and analyzing performance.
Features
- Use as a decorator or context manager
- Nested timing support with proper indentation
- Detailed logging of start and end times
- Statistical analysis of execution times across multiple runs
- Customizable task names with support for dynamic formatting
- Lightweight and easy to integrate into existing projects
Installation
Install Todd's Timer using pip:
pip install todds_timer
Usage
At the top of your python file, import the Timer class and configure logging.
Standard timing messages are logged at the DEBUG level, however the summary table
produced by print_average_times() is at the INFO level.
from todds_timer import Timer
import logging
logging.basicConfig(level=logging.DEBUG, format="%(levelname)s %(message)s")
As a Context Manager
with Timer("Calculating sum"):
result = sum([1,2,3,4])
Output:
DEBUG ----STARTED Calculating sum
DEBUG ----COMPLETED (in 0.000 seconds) Calculating sum
As a Decorator
@Timer("Calculate sum of {0} and {1}")
def add_numbers(a, b):
return a + b
result = add_numbers(5, 7)
Output:
DEBUG ----STARTED Calculate sum of 5 and 7
DEBUG ----COMPLETED (in 0.000 seconds) Calculate sum of 5 and 7
Nested Timers
with Timer("Outer operation"):
# Some code here
with Timer("Inner operation"):
# More code here
pass
Output:
DEBUG ----STARTED Outer operation
DEBUG --------STARTED Inner operation
DEBUG --------COMPLETED (in 0.000 seconds) Inner operation
DEBUG ----COMPLETED (in 0.000 seconds) Outer operation
Analyzing Timing Results
# After running some timed operations
Timer.print_average_times(sort="name")
Output:
INFO Average | Minimum | Maximum | Count | Task name
INFO 0.000 | 0.000 | 0.000 | 1 | Calculate sum of 5 and 7
INFO 0.000 | 0.000 | 0.000 | 1 | Calculating sum
INFO 0.000 | 0.000 | 0.000 | 1 | Inner operation
INFO 0.000 | 0.000 | 0.000 | 1 | Outer operation
Configuration
Todd's Timer uses Python's built-in logging module. To see the timing output, ensure that your logging is configured to show DEBUG level messages:
import logging
logging.basicConfig(level=logging.DEBUG)
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Metadata
Release files for todds-timer 2025.9.12
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| todds_timer-2025.9.12.tar.gz | 11.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| todds_timer-2025.9.12-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 18.2 kB
Release files / todds_timer-2025.9.12.tar.gz
| Download URL | todds_timer-2025.9.12.tar.gz |
|---|---|
| Size | 11.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d9942f16c65bd1a6c9759d42eb6a126fa6191c00316d9b7cccd9197949470717
|
|
BLAKE2b-256 checksum How to use checksums |
adfedb36951b6fab9f9389d41c2a200a5cac4c1e5eb30d1af90752b271cedd2f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 12, 2025.
Transparency logRelease files / todds_timer-2025.9.12-py3-none-any.whl
| Download URL | todds_timer-2025.9.12-py3-none-any.whl |
|---|---|
| Size | 7.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
daf069ffb1a2f85ded275bb5acfccad1b85fdb25ff2a7ce7ae8fb08ed3379d8a
|
|
BLAKE2b-256 checksum How to use checksums |
f94bd35301bb2b4ec744a634ceb390901351041d1262a9a1f6be02cf7840b2fd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 12, 2025.
Transparency log