Skip to main content

Stdlib-only measurement primitives — stopwatch, rate estimation, ETA prediction.

Project description

codechu-meter

   ___          _           _
  / __\___   __| | ___  ___| |__  _   _
 / /  / _ \ / _\` |/ _ \/ __| '_ \| | | |
/ /__| (_) | (_| |  __/ (__| | | | |_| |
\____/\___/ \__,_|\___|\___|_| |_|\__,_|

Stdlib-only measurement primitives — stopwatch, rolling-window rate estimator, ETA predictor — extracted from the Disk Cleaner toolchain. Depends only on codechu-fmt for pretty __str__ rendering. Python 3.10+.

Install

pip install codechu-meter

API

Stopwatch

from codechu_meter import Stopwatch

with Stopwatch() as sw:
    do_work()
print(sw)          # → '1m 30s'  (via codechu-fmt)
print(sw.elapsed)  # → float seconds

# Manual form
sw = Stopwatch().start()
do_work()
sw.stop()

RateEstimator

from codechu_meter import RateEstimator

re = RateEstimator(window_seconds=1.0)
for chunk in stream:
    re.observe(len(chunk))
print(re.rate())   # float per-second
print(re)          # → '1.2 MB/s' if unit='bytes'

Pass unit='items' (default), 'bytes', 'ops', or any custom label — __str__ delegates to codechu_fmt.format_rate.

ETAEstimator

from codechu_meter import ETAEstimator

eta = ETAEstimator(total=1000, mode="ema")
for current in progress:
    eta.update(current)
    print(eta)     # → '45s' or '?' if not enough samples yet

mode='linear' (default) uses overall throughput since construction. mode='ema' blends an exponential moving average of recent throughput for smoother numbers on bursty workloads.

eta() returns None until at least two updates with measurable elapsed time and positive progress; __str__ renders that as '?'.

Design

  • Stdlib + codechu-fmt only. No other dependencies.
  • Monotonic clock. Wall-clock jumps don't break timing.
  • Defensive. Zero progress, zero elapsed, NaN, and negative rates never raise.

Tests

pip install -e ".[dev]"
pytest -q

Coverage gate: ≥90 %. Tests drive time via monkeypatching time.monotonic for deterministic assertions.

License

MIT — see LICENSE.

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

codechu_meter-0.1.0.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

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

codechu_meter-0.1.0-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file codechu_meter-0.1.0.tar.gz.

File metadata

  • Download URL: codechu_meter-0.1.0.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for codechu_meter-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a6cac73ae12d7f889ca58822198578f81afe22e805587c9bbe70580d1d5700cc
MD5 d201849826513f50b97311d55becba82
BLAKE2b-256 76a42498effc55170ce825c6032a2976e06216dff0ce0ce5653f676b9cd601c1

See more details on using hashes here.

Provenance

The following attestation bundles were made for codechu_meter-0.1.0.tar.gz:

Publisher: release.yml on codechu/meter-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file codechu_meter-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: codechu_meter-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for codechu_meter-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ebe17e66fac7b93395de0c0a15ebca66769128a120004dd1b480a540872ccae5
MD5 a1a4c3d2df06928841ec167929b00d72
BLAKE2b-256 f709e2c3fbdfc2e3e2a8c948588f70add9509b76061e63985e2c0eae8c2b580b

See more details on using hashes here.

Provenance

The following attestation bundles were made for codechu_meter-0.1.0-py3-none-any.whl:

Publisher: release.yml on codechu/meter-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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