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.2.0.tar.gz
(4.5 kB
view hashes)
Built Distribution
Close
Hashes for et_stopwatch-1.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cad5ad10f058f3597d5eac399e2a29d6ea0c73742b913cbe1323e9c9dddbf9b4 |
|
MD5 | 435dc3b1bb94c269cd79240899050612 |
|
BLAKE2b-256 | 89c429d1047636dc7771ed7f88dce7b36e11e43f3a7d127f9a26986525a1a980 |