TimeRun is a Python library for elapsed time measurement.
Project description
TimeRun - Python library for elapsed time measurement.
TimeRun is a simple, yet elegant elapsed time measurement library for Python. It is distributed as a single file module and has no dependencies other than the Python Standard Library.
- Elapsed Time: Customized time delta which represents elapsed time in nanoseconds
- Stopwatch: An elapsed time measurer with the highest available resolution
- Timer: Convenient syntax to capture and save measured elapsed time results
Setup
Prerequisites
The only prerequisite to use TimeRun is running Python 3.9+.
Installation
Install TimeRun from Python Package Index:
pip install timerun
Install TimeRun from Source Code:
pip install git+https://github.com/HH-MWB/timerun.git
Quickstart
Measure Code Block
>>> import time
>>> from timerun import Timer
>>> with Timer() as timer:
... time.sleep(0.1) # your code here
>>> print(timer.duration)
0:00:00.100000000
Measure Function
>>> import time
>>> from timerun import Timer
>>> timer = Timer()
>>> @timer
... def func():
... time.sleep(0.1) # your code here
>>> func()
>>> print(timer.duration)
0:00:00.100000000
Measure Async Function
>>> import asyncio
>>> from timerun import Timer
>>> timer = Timer()
>>> @timer
... async def async_func():
... await asyncio.sleep(0.1) # your code here
>>> asyncio.run(async_func())
>>> print(timer.duration)
0:00:00.100000000
Measure Async Code Block
>>> import asyncio
>>> from timerun import Timer
>>> async def async_code():
... async with Timer() as timer:
... await asyncio.sleep(0.1) # your code here
... print(timer.duration)
>>> asyncio.run(async_code())
0:00:00.100000000
Multiple Measurements
>>> import time
>>> from timerun import Timer
>>> timer = Timer()
>>> with timer:
... time.sleep(0.1) # your code here
>>> with timer:
... time.sleep(0.1) # your code here
>>> print(timer.duration) # Last duration
0:00:00.100000000
>>> print(timer.durations) # All durations
(ElapsedTime(nanoseconds=100000000), ElapsedTime(nanoseconds=100000000))
Advanced Options
>>> from timerun import Timer
>>> # Exclude sleep time from measurements
>>> timer = Timer(count_sleep=False)
>>> # Limit storage to last 10 measurements
>>> timer = Timer(max_len=10)
Contributing
We welcome contributions! Please see CONTRIBUTING.md for guidelines on how to contribute to this project.
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.4.0.tar.gz.
File metadata
- Download URL: timerun-0.4.0.tar.gz
- Upload date:
- Size: 12.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
89370345a065a6bc9ea899a4d329acb301ccd21d617c2496d1982f057c009c31
|
|
| MD5 |
9a8f89906f32ffe5f33b2491ada88054
|
|
| BLAKE2b-256 |
9b97fea3b5648f47da81baa3a3b3ccfc1daeffd53155858e2a17cd092e826a62
|
Provenance
The following attestation bundles were made for timerun-0.4.0.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.4.0.tar.gz -
Subject digest:
89370345a065a6bc9ea899a4d329acb301ccd21d617c2496d1982f057c009c31 - Sigstore transparency entry: 854207237
- Sigstore integration time:
-
Permalink:
HH-MWB/timerun@24add9e1db3d8ab0a11617c560a96d784d1bcd12 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/HH-MWB
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@24add9e1db3d8ab0a11617c560a96d784d1bcd12 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file timerun-0.4.0-py3-none-any.whl.
File metadata
- Download URL: timerun-0.4.0-py3-none-any.whl
- Upload date:
- Size: 7.5 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 |
236b8cc0486e53d242763e8454bcebd0aa420ee7bb6a3043d0c60082e8303c62
|
|
| MD5 |
6f579c1796f1c4241405f037e8fd3cfa
|
|
| BLAKE2b-256 |
62418fc1a68ac5dc5e78fbac5887b993b6562001674b63902d5e49ee3de95c3c
|
Provenance
The following attestation bundles were made for timerun-0.4.0-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.4.0-py3-none-any.whl -
Subject digest:
236b8cc0486e53d242763e8454bcebd0aa420ee7bb6a3043d0c60082e8303c62 - Sigstore transparency entry: 854207277
- Sigstore integration time:
-
Permalink:
HH-MWB/timerun@24add9e1db3d8ab0a11617c560a96d784d1bcd12 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/HH-MWB
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@24add9e1db3d8ab0a11617c560a96d784d1bcd12 -
Trigger Event:
workflow_dispatch
-
Statement type: