⏳ Timer for Python ⌛️
Lightweight Python package that makes it easy to measure how much time it takes to run Python programs and gauge performance of multiple, smaller bits of code.
Ready to try? Learn how to install and find tutorials in the user guide.
Getting Started
Basics
Simply add the Timer to your imports, and then wrap the Timer function around your code to measure the performance of the executed block of code:
from timer import Timer
timer = Timer()
timer.start()
# Insert your code here
timer.stop() # Output example: 12.34 seconds
Context Manager
Alternatively, use the with statement. This will automatically start and stop the clock – and so no need to declare timer.start() and timer.stop(). Same result as before, but less code:
with Timer():
# Insert your code here
# Output example: 12.34 seconds
Decorator
Or use the function_timer as a function decorator:
from timer import function_timer
@function_timer()
def test_function():
# Insert your code here
test_function()
# Output example: 12.34 seconds for thread TEST_FUNCTION
Core Features
Decimals
Instead of the default value of 2 for decimals``, you can set the output precision up to 9in thedecimals` parameter:
timer = Timer()
timer.start(decimals=5)
# Insert your code here
timer.stop() # Output example: 0.12345 seconds
Multiple Threads
Imagine that you want to troubleshoot which parts of your code are performing better or worse. Or do you want to split-test the performance of different methods? Timer for Python is a quick, easy way to get the job done.
To measure the performance of multiple blocks of code, use the thread parameter to name different threads:
timer = Timer()
timer.start(thread="A")
# Insert your code here
timer.start(thread="B", decimals=5)
# Insert more code here
timer.stop(thread="B") # Output example: 0.12345 seconds for thread B
# Insert even more code here
timer.stop(thread="A") # Output example: 6.78 seconds for thread A
Or use the with statement to get the same result with less code:
with Timer(thread="A")
# Insert your code here
with Timer(thread="B", decimals=5):
# Insert more code here
# Output example: 0.12345 seconds for thread B
# Insert even more code here
# Output example: 6.78 seconds for thread A
Become a Sponsor 🏅
If you find this project helpful, please consider supporting its development. Your donations will help keep it alive and growing. Every contribution makes a difference, whether you buy a coffee or support with a monthly donation. Find your tier here:
Thank you for your support! 🙌
Contribute
If you have suggestions or changes to the module, feel free to add to the code and create a pull request.
Report Bugs
If you encounter any issues, you can report them as bugs or raise issues.
Metadata
Release files for timer-for-python 0.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 | |
|---|---|---|---|
| timer_for_python-0.9.12.tar.gz | 10.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| timer_for_python-0.9.12-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 26.1 kB
Release files / timer_for_python-0.9.12.tar.gz
| Download URL | timer_for_python-0.9.12.tar.gz |
|---|---|
| Size | 10.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c76112e1776d26b0d13d48bc6d2a51768b66c8a234d7b9b3e9134a9cf5dfab81
|
|
BLAKE2b-256 checksum How to use checksums |
75176ed656039195545e02acd5047731558116097681cf41b97ea6f5648abb03
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Aug 22, 2026.
Transparency logRelease files / timer_for_python-0.9.12-py3-none-any.whl
| Download URL | timer_for_python-0.9.12-py3-none-any.whl |
|---|---|
| Size | 15.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
93ae6f4d56684542240edb86c29c13356796445842146b56de3679ab7c15ebff
|
|
BLAKE2b-256 checksum How to use checksums |
a2f1f832cfe0eb14ffeacb0c1d3bbb72739af873f2956d4c35d54c7ccff919ee
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Aug 22, 2026.
Transparency log