Skip to main content

py-stopwatch

https://img.shields.io/pypi/v/py-stopwatch?color=success Documentation Status Python Version Support GitHub Issues GitHub Followers Twitter Followers

Stopwatch class for timing portions of python code.

Features

  • Tick-based stopwatch

  • Support for Pause/Resume

  • Support for multiple named-ticks

  • Utility functions for time between different ticks

  • No third party requirements.

Usage

from stopwatch import Stopwatch
t = Stopwatch()
t.start()
print("Started ..")
time.sleep(0.24)
print(f"t.tick(): {t.tick():.4f} seconds")
time.sleep(0.48)
print(f"t.tick(): {t.tick():.4f} seconds")
time.sleep(0.16)
print(f"t.tick('Named Tick-1'): {t.tick('Named Tick-1'):.4f} seconds")
t.pause()
print("Paused ..")
time.sleep(0.12)
t.resume()
print("Resumed ..")
print(f"t.last(): {t.last():.4f} seconds")
time.sleep(0.12)
print(f"t.tick(): {t.tick():.4f} seconds")
time.sleep(0.12)
print(f"t.tick('Named Tick-2'): {t.tick('Named Tick-2'):.4f} seconds")
t.stop()
print("Timer stopped.")
print("---")
print(f"Total pause: {t.time_paused:.2f} seconds.")
print(f"Total runtime: {t.time_active:.2f} seconds.")
print(f"Total time: {t.time_total:.2f} seconds.")
tij = t.get_time_elapsed(start_key='Named Tick-1', end_key='Named Tick-2')
print(f"Time between 'Named Tick-1' and 'Named Tick-2': {tij:.4f}")

History

1.0.1 (2025-12-11)

  • Improve CI matrix and drop failing Python 3.7 job.

  • Fix Sphinx configuration and RTD build (language and theme deps).

  • Tidy stopwatch implementation for style (flake8) and clarity.

1.0.0 (2025-12-10)

  • First stable release.

  • Add unit tests, CI configuration, and timing bugfixes.

0.2.2 (2024-11-27)

  • Fix precision setting not taking effect in some cases.

  • Packaging and configuration updates.

0.2.1 (2024-11-27)

  • Fix search behaviour when using string keys (strings being iterable).

0.2.0 (2024-11-27)

  • Add a precision setting for timestamps.

  • Add Stopwatch.get_ticks(...) helper to search ticks.

  • Documentation updates and minor internal cleanups.

0.1.1 (2022-02-10)

  • Fix PyPI upload issue due to history formatting.

0.1.0 (2022-02-10)

  • Internal refactors and documentation improvements.

0.0.3 (2022-01-24)

  • Replace namedtuple with dataclasses for ticks.

  • Use time.perf_counter for timing.

  • Miscellaneous bug fixes and improvements.

0.0.2 (2021-04-12)

  • Minor fixes and documentation updates.

0.0.1 (2021-04-13)

  • First release on PyPI.

Metadata

Release files for py-stopwatch 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for py-stopwatch 1.0.1
File Size Uploaded Provenance Actions
py_stopwatch-1.0.1.tar.gz 13.7 kB Without provenance Details for py_stopwatch-1.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for py-stopwatch 1.0.1
File Interpreter ABI Platform Actions
py_stopwatch-1.0.1-py2.py3-none-any.whl Python 3, Python 2 none any Details for py_stopwatch-1.0.1-py2.py3-none-any.whl

Total release size: 20.7 kB

Release files / py_stopwatch-1.0.1.tar.gz

Download URL py_stopwatch-1.0.1.tar.gz
Size 13.7 kB
Tags Source
SHA-256 checksum
How to use checksums
a44e1a59db0220fbb13eb2e23058d3e43b8fc1204bef115dd5c9c2a541adddfa
BLAKE2b-256 checksum
How to use checksums
618f4e631b96d0f157689f5bd3dc41586798736101ddbb2ab7ac0322c32b1d66
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.5

Release files / py_stopwatch-1.0.1-py2.py3-none-any.whl

Download URL py_stopwatch-1.0.1-py2.py3-none-any.whl
Size 6.9 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
e85f18ea23f1ffd99d81af7fe6115579c76d7d1f727f0e666168a910a94021a7
BLAKE2b-256 checksum
How to use checksums
93fb373a6cd333d64da3364afc91b002fdc859ba122c7e06823edce3001fbf79
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.5

Security for py-stopwatch 1.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page