Skip to main content

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...done. (4.0s)

Print with varying precision:

with CTimer("Waking up", 3):
    sleep(4.123456)
Waking up...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...
    cooking eggs...done. (3.0s)
    pouring juice...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...
    : 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...
    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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cleantimer-0.0.1.tar.gz (14.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cleantimer-0.0.1-py3-none-any.whl (15.1 kB view details)

Uploaded Python 3

File details

Details for the file cleantimer-0.0.1.tar.gz.

File metadata

  • Download URL: cleantimer-0.0.1.tar.gz
  • Upload date:
  • Size: 14.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.7.6

File hashes

Hashes for cleantimer-0.0.1.tar.gz
Algorithm Hash digest
SHA256 35d5e764a832bc638fdbdd1505e80423b16ab35ab577559b7f4c998075ba879e
MD5 67386e0a28067fbe8d24e06f231b901e
BLAKE2b-256 69617580ba35fe89d5783fa7b6db64b808e82129bd36f77f523d9af2e4b049d8

See more details on using hashes here.

File details

Details for the file cleantimer-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: cleantimer-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 15.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.7.6

File hashes

Hashes for cleantimer-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e2d4f51dbbd40902c8dcd1e57ffba1f422925d36bd46e5aa223354963eb3a911
MD5 1f7d4afc5b23430452a102dddb0248dc
BLAKE2b-256 c6494746f114fbaa444b7ad7cdb17e1357916b8f1c1d2eed0a8d9b44ae1914ac

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page