timer

timer is a library to time your Python code.
Installation
pip install timer4 # not timer
Usage
timeruseswithstatement to watch how long your code running:
import time
from timer import Timer
with Timer().watch_and_report(msg='test'):
# running code that do lots of computation
time.sleep(1.0)
# when the code reach this part, it will output the message and the time it tooks.
# for example:
# test: 10.291 seconds
- If you don't want to report the result immediately, use the
watchmethod instead. Whenever you've done, callreport.
import time
from timer import Timer
# you can either create a timer variable first, or use Timer.get_instance()
# that will return a singleton variable.
total = 0
for item in range(7):
# only measure the part that we want
with Timer.get_instance().watch("sum of square"):
total += item ** 2
time.sleep(0.2)
# doing other things that we don't want to measure
time.sleep(0.8)
Timer.get_instance().report()
-
You can also use different way to print the message, such as using logging by passing a printing function to the report method:
report(print_fn=logger.info) -
You can also choose to append the result to a file
report(append_to_file='/tmp/runtime.csv'). This is useful if you want to measure runtime of your method and put it to a file to plot it later.
Metadata
Release files for timer4 1.1.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 | Actions |
|---|---|---|---|---|
| timer4-1.1.0.tar.gz | 3.6 kB | Without provenance | Details for timer4-1.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| timer4-1.1.0-py3-none-any.whl | Python 3 | none | any | Details for timer4-1.1.0-py3-none-any.whl |
Total release size: 8.1 kB
Release files / timer4-1.1.0.tar.gz
| Download URL | timer4-1.1.0.tar.gz |
|---|---|
| Size | 3.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4a93c16a3fec06ac9a3afce92a28ceb7dff514829e1ca6d8b4b3f8287b4b98ba
|
|
BLAKE2b-256 checksum How to use checksums |
3c22ee963fdb5e0e69c7547cfc0e8d66810b0266d025ce82d3395d4362e65b3c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.8.16
|
Release files / timer4-1.1.0-py3-none-any.whl
| Download URL | timer4-1.1.0-py3-none-any.whl |
|---|---|
| Size | 4.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
23d635ab721c04cc36b0a38333993bf057ebcb8067dd1b02c53d1c9b842f8ec8
|
|
BLAKE2b-256 checksum How to use checksums |
1ab0cdd988729dcb76839b36aa970746361ce3e8a5e78ce552a2ffd20d9a05d3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.8.16
|
Security for timer4 1.1.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.