Track progress of long-running scripts, without cluttering your code with log statements.
Project description
cleantimer
Track progress of long-running scripts, without cluttering your code with log statements.
cleantimer is a minimal wrapper around a couple of my favorite packages for timing scripts - contexttimer and tqdm. It merges their most useful features in a clean API based simply on the way I've found I like to use them. Hopefully you find it simply useful. ๐
Installation
pip install cleantimer
Import:
from cleantimer import CTimer
Use cases
A basic timer with a message for what you're timing:
with CTimer("Waking up"):
sleep(4)
Waking up (3:22PM)...done. (4.0s)
Print with varying precision:
with CTimer("Waking up", 3):
sleep(4.123456)
Waking up (3:22PM)...done. (4.123s)
Sub-timers
with CTimer("Making breakfast") as timer:
sleep(2)
with timer.child("cooking eggs") as eggtimer:
sleep(3)
with timer.child("pouring juice"):
sleep(1)
Making breakfast (3:22PM)...
cooking eggs (3:22PM)...done. (3.0s)
pouring juice (3:23PM)...done. (1.0s)
done. (6.0s)
Progress meter on a Pandas apply
df = pd.DataFrame({"A": list(range(10000))})
def times2(row): return row["A"] * 2
with CTimer("Computing doubles") as timer:
df["2A"] = timer.progress_apply(df, times2)
Computing doubles (3:22PM)...
: 100% โโโโโโโโโโโโโโโโโโโโโโโโโโ 10000/10000 [00:07<00:00, 135869it/s]
done. (7.4s)
Segmented progress meter
df = pd.DataFrame({"A": list(range(10000)), "type": [1]*5000 + [2]*5000})
def times2(row): return row["A"] * 2
with CTimer("Computing doubles") as timer:
df["2A"] = timer.progress_apply(df, times2, split_col="type", message="part {}")
Computing doubles (3:22PM)...
part 1: 100% โโโโโโโโโโโโโโโโโโโโโโโโโโ 5000/5000 [00:07<00:00, 135869it/s]
part 2: 100% โโโโโโโโโโโโโโโโโโโโโโโโโโ 5000/5000 [00:07<00:00, 122854it/s]
done. (8.2s)
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cleantimer-0.0.2.tar.gz.
File metadata
- Download URL: cleantimer-0.0.2.tar.gz
- Upload date:
- Size: 17.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
91e0a8e1708a2ef19eae3085b3dfe9d1831309648f07d783bc9aaedb37072f3a
|
|
| MD5 |
0e6f62945138449281c932bec6bce136
|
|
| BLAKE2b-256 |
f1b71211ff034d28971b8c7365a5fafe78d83232e653888a192620df55e7fdb8
|
File details
Details for the file cleantimer-0.0.2-py3-none-any.whl.
File metadata
- Download URL: cleantimer-0.0.2-py3-none-any.whl
- Upload date:
- Size: 16.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d692774600faff7b1eac56eb77ed722d288651c05ac1afc4d0b6b6aabdf9848d
|
|
| MD5 |
a2f9d98482817712db61fdf54644976e
|
|
| BLAKE2b-256 |
27aad3c9d95f48303f951b5210b3042dcb6d6fffd5270867c2e02c0a5f9b68fc
|