Latest Socket ResearchMalicious Chrome Extension Performs Hidden Affiliate Hijacking.Details
Socket
Book a DemoInstallSign in
Socket

timerun

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

timerun

TimeRun is a Python library for elapsed time measurement.

pipPyPI
Version
0.2.0
Maintainers
1

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.

Keywords

time

FAQs

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts