Measure the amount of time that elapses between lap times
Project description
la-stopwatch
Measure the amount of time that elapses between lap times.
install
pip install la-stopwatch
usage
There is two versions of stopwatch:
StopwatchNS
Stopwatch
While both measure using nanoseconds, the second option convert nanoseconds to timedelta
before returning any time measurement. All examples will be using Stopwatch
but both have the same methods.
Time start when Stopwatch
is created.
from la_stopwatch import Stopwatch
stopwatch = Stopwatch()
with open("filename", "r") as f:
raw = f.readlines()
print(stopwatch.duration()) # 0:00:00.000292
print(stopwatch) # same as above
Record each lap time for future analysis.
from la_stopwatch import Stopwatch
stopwatch = Stopwatch()
with open("filename1", "r") as f:
raw = f.readlines()
stopwatch.record()
with open("filename2", "r") as f:
raw = f.readlines()
stopwatch.record()
with open("filename3", "r") as f:
raw = f.readlines()
stopwatch.record("last record")
# Dictionary with all records
print(stopwatch.get_records())
# First record in the dictionary
print(stopwatch.get_record(0))
# Record with name "last record"
print(stopwatch.get_record("last record"))
Some methods return the Stopwatch
so you can chain method calls. For example, you can record how much time take to open each file if you reset every time after recording.
from la_stopwatch import Stopwatch
stopwatch = Stopwatch()
with open("filename1", "r") as f:
raw = f.readlines()
stopwatch.record().reset()
with open("filename2", "r") as f:
raw = f.readlines()
stopwatch.record()
print(stopwatch.get_record(0))
print(stopwatch.get_record(1))
Use log()
method to log the duration.
from logging import basicConfig
from la_stopwatch import Stopwatch
# To show log level DEBUG
basicConfig(level=0)
stopwatch = Stopwatch()
with open("filename", "r") as f:
raw = f.readlines()
stopwatch.log("Duration: %(duration)s")
There is support for context manager.
from la_stopwatch import Stopwatch
with Stopwatch("Duration: %(duration)s"):
with open("filename", "r") as f:
raw = f.readlines()
And support for decorator.
from la_stopwatch import Stopwatch
@Stopwatch("Duration: %(duration)s")
def open_file():
with open("filename", "r") as f:
raw = f.readlines()
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
Built Distribution
Hashes for la_stopwatch-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b34d90a9b9d85949b22113146bfb55fca3f2b58d780f661ab3cc223049c2a212 |
|
MD5 | 0319436d816db1d6011aca66bcb7618e |
|
BLAKE2b-256 | 76f41144a0d37d6d1695786c0dff4e45d76c041e1e88bd82b55b93ce36f78679 |