Lightweight 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
Project description
⏳ 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.
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
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 timer_for_python-0.9.9.tar.gz.
File metadata
- Download URL: timer_for_python-0.9.9.tar.gz
- Upload date:
- Size: 10.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4a7bbe21fb8dbf71bb1960cf16510d12455f971762817f0451ee80a7f48ede77
|
|
| MD5 |
44900b45a9421fba18eb6299b84c245f
|
|
| BLAKE2b-256 |
2ac8b0dd4c197663643917e742493fd79db8254b7330d86f3e5b5ca0697b1b4a
|
Provenance
The following attestation bundles were made for timer_for_python-0.9.9.tar.gz:
Publisher:
release.yml on jakob-bagterp/timer-for-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
timer_for_python-0.9.9.tar.gz -
Subject digest:
4a7bbe21fb8dbf71bb1960cf16510d12455f971762817f0451ee80a7f48ede77 - Sigstore transparency entry: 942223142
- Sigstore integration time:
-
Permalink:
jakob-bagterp/timer-for-python@e3f78d838f4bc3ebdbfe7ac3818a7c4ef90df092 -
Branch / Tag:
refs/tags/v0.9.9 - Owner: https://github.com/jakob-bagterp
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@e3f78d838f4bc3ebdbfe7ac3818a7c4ef90df092 -
Trigger Event:
push
-
Statement type:
File details
Details for the file timer_for_python-0.9.9-py3-none-any.whl.
File metadata
- Download URL: timer_for_python-0.9.9-py3-none-any.whl
- Upload date:
- Size: 15.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
93d28edcc8bcde14027bada2b710dfa91daf585270928c53083039be436490b0
|
|
| MD5 |
d4adc511dfd3a1b86a1c99a56e225d03
|
|
| BLAKE2b-256 |
c5fd50445aff7e5e84b50a84a96fe95a3ea129efe4343cd982b5e21850275e3c
|
Provenance
The following attestation bundles were made for timer_for_python-0.9.9-py3-none-any.whl:
Publisher:
release.yml on jakob-bagterp/timer-for-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
timer_for_python-0.9.9-py3-none-any.whl -
Subject digest:
93d28edcc8bcde14027bada2b710dfa91daf585270928c53083039be436490b0 - Sigstore transparency entry: 942223161
- Sigstore integration time:
-
Permalink:
jakob-bagterp/timer-for-python@e3f78d838f4bc3ebdbfe7ac3818a7c4ef90df092 -
Branch / Tag:
refs/tags/v0.9.9 - Owner: https://github.com/jakob-bagterp
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@e3f78d838f4bc3ebdbfe7ac3818a7c4ef90df092 -
Trigger Event:
push
-
Statement type: