Skip to main content

A super simple utility to time your python code.

Project description

clockit

clockit

A super lightweight utility to time your Python code — nothing more, nothing less.

usage

Install with pip install clockit-code or with uv pip install clockit-code.

Then import with from clockit import clockit

Example 1: Timing Data Loading

from clockit import clockit
import pandas as pd

with clockit(name="load csv") as ct:
    df = pd.read_csv("big_data.csv")
print(ct)  # load csv: X.XXX seconds

Example 2: Timing Model Training

from clockit import clockit
from sklearn.ensemble import RandomForestClassifier

X, y = ...  # your features and labels
model = RandomForestClassifier()

with clockit(printer=print, name="fit model") as ct:
    model.fit(X, y)
# Output: fit model: X.XXX seconds

Example 3: Batch Processing with Nested Timers

from clockit import clockit
import time

data_batches = [range(1000), range(1000), range(1000)]

with clockit(printer=print, name="total batch processing") as ct_total:
    for i, batch in enumerate(data_batches):
        with clockit(printer=print, name=f"process batch {i+1}") as ct:
            time.sleep(0.5)  # simulate processing
print(ct_total)  # total batch processing: X.XXX seconds

Example 4: Accessing Raw Timing Data

with clockit() as ct:
    # expensive operation
    ...
print(ct.elapsed)   # 1.234 (float seconds)
print(ct.readout)   # 'Time: 1.234 seconds'

Example 5: Custom Formatting

# Custom formatting
def my_printer(msg):
    print(f"⏱️  {msg}")

with clockit(printer=my_printer) as ct:
    time.sleep(1)

See more examples in examples.ipynb

why clockit?

  • 🪶 Lightweight: zero dependencies, minimal footprint
  • 🧩 Drop-in: works anywhere
  • 🤫 Silent by default, but easy to log or print
  • 🏗️ Perfect for steps, scripts, or experiments
  • 🕶️ No configuration, no boilerplate, just timing

Limitations

  • Wall-clock time only:
    • clockit uses time.perf_counter(), which measures elapsed (wall) time, not CPU time. This includes time spent sleeping or waiting on I/O.
  • Single-threaded timing:
    • clockit does not account for parallel or asynchronous execution. If your code spawns threads, processes, or async tasks, the timer only tracks the main context and won't reflect per-task durations or concurrency effects.
  • No GPU/CUDA synchronization:
    • For GPU workloads (e.g., PyTorch, TensorFlow), clockit does not synchronize with CUDA or other accelerators. Measured time may not reflect actual device execution time unless you manually synchronize before/after timing.

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

clockit_code-0.1.2.tar.gz (444.3 kB view details)

Uploaded Source

Built Distribution

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

clockit_code-0.1.2-py3-none-any.whl (3.0 kB view details)

Uploaded Python 3

File details

Details for the file clockit_code-0.1.2.tar.gz.

File metadata

  • Download URL: clockit_code-0.1.2.tar.gz
  • Upload date:
  • Size: 444.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.19

File hashes

Hashes for clockit_code-0.1.2.tar.gz
Algorithm Hash digest
SHA256 f6b96ba5ad77a554ee03a4b962eae2f5caffb55ff6053d7512f1adcdcefa2154
MD5 47f74292fad1f4bc204f1cc6e98e277e
BLAKE2b-256 9db3493a056a06a38404d6a6c50348a6ff67f1fb4773d22d9cda469cce0b1d14

See more details on using hashes here.

File details

Details for the file clockit_code-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for clockit_code-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a583ccada36e14c2bf592af0004830a9e9b6a7953cb2feaf0490f0fed575d5b0
MD5 8f036c889bca393fe88697aac88bcced
BLAKE2b-256 a08d096206c2a0b62429dc6e86adbdcb9ad4459f2a2fcde226a53cd25ca392bf

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