Skip to main content

TimeRun is a Python library for elapsed time measurement.

Project description

TimeRun

TimeRun - Python library for elapsed time measurement.

Version Status License Coverage Total Downloads

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

timerun-0.4.0.tar.gz (12.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

timerun-0.4.0-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

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

Hashes for timerun-0.4.0.tar.gz
Algorithm Hash digest
SHA256 89370345a065a6bc9ea899a4d329acb301ccd21d617c2496d1982f057c009c31
MD5 9a8f89906f32ffe5f33b2491ada88054
BLAKE2b-256 9b97fea3b5648f47da81baa3a3b3ccfc1daeffd53155858e2a17cd092e826a62

See more details on using hashes here.

Provenance

The following attestation bundles were made for timerun-0.4.0.tar.gz:

Publisher: release.yaml on HH-MWB/timerun

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for timerun-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 236b8cc0486e53d242763e8454bcebd0aa420ee7bb6a3043d0c60082e8303c62
MD5 6f579c1796f1c4241405f037e8fd3cfa
BLAKE2b-256 62418fc1a68ac5dc5e78fbac5887b993b6562001674b63902d5e49ee3de95c3c

See more details on using hashes here.

Provenance

The following attestation bundles were made for timerun-0.4.0-py3-none-any.whl:

Publisher: release.yaml on HH-MWB/timerun

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page