TimeRun is a Python library for time measurements.
Project description
TimeRun — Python package for time measurement.
TimeRun is a single-file Python package with no dependencies beyond the standard library. It records wall-clock time and CPU time for code blocks or function calls and supports optional metadata (e.g. run id, tags) per measurement.
For the full value proposition and positioning, see Why TimeRun on the docs site.
Installation
From PyPI:
pip install timerun
From source:
pip install git+https://github.com/HH-MWB/timerun.git
Note: Requires Python 3.10+.
Usage
Time Code Block
Use with Timer() as m: (or async with). The yielded Measurement has wall_time and cpu_time:
>>> from timerun import Timer
>>> with Timer() as m:
... pass # code block to be measured
...
>>> m.wall_time.timedelta
datetime.timedelta(microseconds=11)
>>> m.cpu_time.timedelta
datetime.timedelta(microseconds=8)
Note: On block exit the timer records CPU time first, then wall time, so wall time is slightly larger than CPU time even when there is no I/O or scheduling.
Time Function Calls
Use @Timer(). One Measurement per call is appended to the callable’s measurements deque:
>>> from timerun import Timer
>>> @Timer()
... def func(): # function to be measured
... return
...
>>> func()
>>> func.measurements[-1].wall_time.timedelta
datetime.timedelta(microseconds=11)
>>> func.measurements[-1].cpu_time.timedelta
datetime.timedelta(microseconds=8)
Note: Argument maxlen caps how many measurements are kept (e.g. @Timer(maxlen=10)). By default the deque is unbounded.
Callbacks on Start and End
Optional on_start and on_end callbacks run once per measurement. Both receive the measurement instance (on_start before timings are set, on_end after). Typical uses are logging, forwarding to OpenTelemetry, or enqueueing to a metrics pipeline.
>>> from timerun import Timer
>>> with Timer(on_end=lambda m: print(m.wall_time.timedelta)):
... pass # code block to be measured
...
0:00:00.000008
Contributing
Contributions are welcome. See CONTRIBUTING.md for setup, testing, and pull request guidelines.
License
This project is licensed under the MIT License — see the LICENSE file for details.
Project details
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 timerun-0.6.1.tar.gz.
File metadata
- Download URL: timerun-0.6.1.tar.gz
- Upload date:
- Size: 7.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 |
36ec23b48b8cd8cbdb83349407ff2727db124901ec1079b194713b9a0aed63ea
|
|
| MD5 |
1434c91e34b9871746f78ba5d977dfad
|
|
| BLAKE2b-256 |
48672e08d42b7ed762c9bd58f9b42877d80a2d2aad8139718ecf1191ceb5f702
|
Provenance
The following attestation bundles were made for timerun-0.6.1.tar.gz:
Publisher:
release.yaml on HH-MWB/timerun
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
timerun-0.6.1.tar.gz -
Subject digest:
36ec23b48b8cd8cbdb83349407ff2727db124901ec1079b194713b9a0aed63ea - Sigstore transparency entry: 1070936866
- Sigstore integration time:
-
Permalink:
HH-MWB/timerun@7f343ef07d1c07c55ddd43a0e56812dc442d346f -
Branch / Tag:
refs/tags/v0.6.1 - Owner: https://github.com/HH-MWB
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@7f343ef07d1c07c55ddd43a0e56812dc442d346f -
Trigger Event:
release
-
Statement type:
File details
Details for the file timerun-0.6.1-py3-none-any.whl.
File metadata
- Download URL: timerun-0.6.1-py3-none-any.whl
- Upload date:
- Size: 7.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 |
6529ac06d61583727ec2b0b4b6cdaaef30b7e68778dbe5b92c263c0a299d0718
|
|
| MD5 |
f45df50325416506852d7691202da69d
|
|
| BLAKE2b-256 |
d9396856d6535af2dee640df84eae91985144e5772c84e690f62b511a8c4beeb
|
Provenance
The following attestation bundles were made for timerun-0.6.1-py3-none-any.whl:
Publisher:
release.yaml on HH-MWB/timerun
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
timerun-0.6.1-py3-none-any.whl -
Subject digest:
6529ac06d61583727ec2b0b4b6cdaaef30b7e68778dbe5b92c263c0a299d0718 - Sigstore transparency entry: 1070936906
- Sigstore integration time:
-
Permalink:
HH-MWB/timerun@7f343ef07d1c07c55ddd43a0e56812dc442d346f -
Branch / Tag:
refs/tags/v0.6.1 - Owner: https://github.com/HH-MWB
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@7f343ef07d1c07c55ddd43a0e56812dc442d346f -
Trigger Event:
release
-
Statement type: