A class for timing code (start/stop, context manager, decorator).
Project description
A class for timing code. A Stopwatch object can be used to time code using its start and stop methods:
from et_stopwatch import Stopwatch stopwatch = Stopwatch() # create and start the stopwatch sleep(1) stopwatch.stop() print(stopwatch) stopwatch : 1.003744 s
Use as a context manager:
with Stopwatch(message='This took') as sw: # using a custom message for i in range(3): sleep(1) print(i, sw.stop(), 's') # stop() returns the time since the last call to start|stop in seconds 0 1.004943 1 1.004948 2 1.003404 This took : total : 3.013295 s minimum: 1.003404 s maximum: 1.004948 s mean : 1.004432 s stddev : 0.000727 s count : 3
Since stop was called more than once, some statistics are printed.
Use as a decorator:
@Stopwatch(name="say_hi_and_sleep_two_seconds", ndigits=3) # custom message, print only 3 digits. def say_hi_and_sleep_two_seconds(): print("hi") sleep(2) say_hi_and_sleep_two_seconds() hi say_hi_and_sleep_two_seconds : 2.003 s
Free software: MIT license
Documentation: https://et-stopwatch.readthedocs.io.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
et_stopwatch-1.3.1.tar.gz
(5.0 kB
view details)
Built Distribution
File details
Details for the file et_stopwatch-1.3.1.tar.gz
.
File metadata
- Download URL: et_stopwatch-1.3.1.tar.gz
- Upload date:
- Size: 5.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.2 CPython/3.9.5 Darwin/22.2.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6e4bbb86d11476d776f63d062638a69c1ffffd0be4baef8a241df3c5c1176952 |
|
MD5 | 8ff3c76a73258bf64bd46cecb7cd3a7d |
|
BLAKE2b-256 | 23c5ed488f649469e03e4b0b0be40b0054963d2d12498be5bf73a29861dad60c |
File details
Details for the file et_stopwatch-1.3.1-py3-none-any.whl
.
File metadata
- Download URL: et_stopwatch-1.3.1-py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.2 CPython/3.9.5 Darwin/22.2.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7744a22c28301fe9602b4abcb368cb33df3d61d60be9d252c8e5bb576f060dff |
|
MD5 | bec1dcf3adb54c6ce9c93772b153e923 |
|
BLAKE2b-256 | 5c0f90ff65a40f5ed3639474d8b2598046e947fa3bc02905afc050c5cd79d726 |