Skip to main content

elapsedtimer

Python elapsed time utilities.

The main interface to this package is an ElapsedTimer class. This class will use the highest resolution timer available to Python depending on the OS, either time.time() or time.clock(). Its purpose is easily to measure and print the duration of a task, and is normally meant to be used as a context manager.

Basic example:

>>> with ElapsedTimer('say hello'):
...     print 'hi there!'
hi there!
13.113 µs: say hello

ElapsedTimer

The constructor for ElapsedTimer takes an optional string describing the operation being performed. It also optionally accepts a file object to change where the resulting duration message will be printed. The output file defaults to sys.stdout.

The constructor can also take a logger instance and log level via the optional logger and loglevel keyword parameters. If a logger is provided, it takes precedence over a file object and the duration message will be output via the logger. The log level defaults to DEBUG.

You can control an ElapsedTimer instance directly instead of using it as a context manager. It has start() and stop() methods. The stop() method will not print the duration for you like exiting a context manager instance does.

There is an elapsed property that returns the elapsed time since start() was called or the context manager entered. A timedelta property is also available that returns the elapsed time as a datetime.timedelta object instead of a float, though note that this class this only has microsecond resolution.

There is a module-level enable variable that acts as a global enable switch for all printing of results by ElapsedTimer. It defaults to True.

Timeout

Another class in the module is Timeout. It adds a few methods to make it easy to check for timeouts. You can use this class as a context manager. The constructor takes the same parameters as for ElapsedTimer, except for a new first param of the timeout in seconds.

There are two methods to check the timeout, check() and check_and_raise(). The former compares the elapsed time against the timeout and returned True if a timeout occurred. The latter will raise TimeoutError if a timeout happens. You can use the timed_out property to as another way to check, equivalent to calling check().

License

This package is licensed under the BSD three-clause license. See the LICENSE file for details.

Copyright © 2014-2022 Chris Reed.

Metadata

Release files for elapsedtimer 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for elapsedtimer 1.0.0
File Size Uploaded Provenance Actions
elapsedtimer-1.0.0.tar.gz 6.1 kB Without provenance Details for elapsedtimer-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for elapsedtimer 1.0.0
File Interpreter ABI Platform Actions
elapsedtimer-1.0.0-py3-none-any.whl Python 3 none any Details for elapsedtimer-1.0.0-py3-none-any.whl

Total release size: 12.3 kB

Release files / elapsedtimer-1.0.0.tar.gz

Download URL elapsedtimer-1.0.0.tar.gz
Size 6.1 kB
Tags Source
SHA-256 checksum
How to use checksums
7f41d31c383232b8a64e55bb5dc8e440a094ba9f0f82eb12461410afe454693c
BLAKE2b-256 checksum
How to use checksums
ab46aae52ed9cfb26a2b8325d116ee66631c0b6880171ba16a125960f4f95cb0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.3

Release files / elapsedtimer-1.0.0-py3-none-any.whl

Download URL elapsedtimer-1.0.0-py3-none-any.whl
Size 6.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f577b94923b3c3867b7e76d751b066a73d14f43e6c01351ecfab082470f01bda
BLAKE2b-256 checksum
How to use checksums
c6adfda1e287d2c6de0b9e05f5b4f5a3045653249e1422689e0a65c2c750dadf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.3

Security for elapsedtimer 1.0.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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page