Skip to main content

A simple stopwatch for measuring code performance

Project description

Stopwatch

A simple stopwatch for measuring code performance.

Examples

import time
from stopwatch import Stopwatch, profile

stopwatch = Stopwatch()
stopwatch.start()
time.sleep(3.0)
stopwatch.stop()
print(stopwatch.elapsed) # 3.003047182224691

with Stopwatch(name='outer') as outer_stopwatch:
    with Stopwatch(name='inner') as inner_stopwatch:
        for i in range(5):
            with inner_stopwatch.lap():
                time.sleep(i / 10)
print(inner_stopwatch.elapsed) # 1.0013675531372428
print(inner_stopwatch.laps) # [3.256136551499367e-05, 0.10015189787372947, 0.20030939625576138, 0.3003752687945962, 0.40049842884764075]
print(outer_stopwatch.report()) # [Stopwatch#outer] total=1.0015s
print(inner_stopwatch.report()) # [Stopwatch#inner] total=1.0014s, mean=0.2003s, min=0.0000s, median=0.2003s, max=0.4005s, dev=0.1416s

@profile(name='wait_for')
def wait_for(ts):
    if not ts:
        return

    time.sleep(ts[0])
    wait_for(ts[1:])

wait_for([0.1, 0.2, 0.3, 0.4, 0.5])
# [profile#wait_for] hits=1, mean=0.0000s, min=0.0000s, median=0.0000s, max=0.0000s, dev=0.0000s
# [profile#wait_for] hits=2, mean=0.2507s, min=0.0000s, median=0.2507s, max=0.5013s, dev=0.2506s
# [profile#wait_for] hits=3, mean=0.4679s, min=0.0000s, median=0.5013s, max=0.9025s, dev=0.3692s
# [profile#wait_for] hits=4, mean=0.6519s, min=0.0000s, median=0.7019s, max=1.2037s, dev=0.4514s
# [profile#wait_for] hits=5, mean=0.8025s, min=0.0000s, median=0.9025s, max=1.4048s, dev=0.5037s
# [profile#wait_for] hits=6, mean=0.9197s, min=0.0000s, median=1.0531s, max=1.5060s, dev=0.5293s

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

python-stopwatch-1.0.0.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

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

python_stopwatch-1.0.0-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file python-stopwatch-1.0.0.tar.gz.

File metadata

  • Download URL: python-stopwatch-1.0.0.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7

File hashes

Hashes for python-stopwatch-1.0.0.tar.gz
Algorithm Hash digest
SHA256 0b2d1caf164b185966da56ce2765bc01f43bb79d105a8408cf4c073bdb0b2fd0
MD5 dd095ac5651cd4d4397155cf9a727a4d
BLAKE2b-256 a8f1fc5b78fcf43e31411a9bc78cf497b8cce4ab7f6e675a41e17503c43b5a76

See more details on using hashes here.

File details

Details for the file python_stopwatch-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: python_stopwatch-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 4.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7

File hashes

Hashes for python_stopwatch-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3a46e0a72e570d2da05aef47df0d0332ed7242b729e9a9b91f7f6765f076161b
MD5 1745de580c7202c0ec5259f3149ecec3
BLAKE2b-256 970149c2463a6635cd23f947a6048c939215f24315dfed3a8360c90962794373

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