Skip to main content

A class for timing code. A Stopwatch object can be used to time code using its start and stop methods:

from et_stopwatch import Stopwatch

stopwatch = Stopwatch() # create and start the stopwatch
sleep(1)
stopwatch.stop()
print(stopwatch)

stopwatch : 1.003744 s

Use as a context manager:

with Stopwatch(message='This took') as sw: # using a custom message
    for i in range(3):
        sleep(1)
        print(i, sw.stop(), 's') # stop() returns the time since the last call to start|stop in seconds

0 1.004943
1 1.004948
2 1.003404
This took :
    total  : 3.013295 s
    minimum: 1.003404 s
    maximum: 1.004948 s
    mean   : 1.004432 s
    stddev : 0.000727 s
    count  : 3

Since stop was called more than once, some statistics are printed.

Use as a decorator:

@Stopwatch(name="say_hi_and_sleep_two_seconds", ndigits=3) # custom message, print only 3 digits.
def say_hi_and_sleep_two_seconds():
    print("hi")
    sleep(2)

say_hi_and_sleep_two_seconds()

hi
say_hi_and_sleep_two_seconds : 2.003 s

Release files for et-stopwatch 1.2.2

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

Source distribution (sdist)

Source distribution for et-stopwatch 1.2.2
File Size Uploaded
et_stopwatch-1.2.2.tar.gz 4.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for et-stopwatch 1.2.2
File Interpreter ABI Platform
et_stopwatch-1.2.2-py3-none-any.whl Python 3 none any Details

Total release size: 10.2 kB

Release files / et_stopwatch-1.2.2.tar.gz

Download URL et_stopwatch-1.2.2.tar.gz
Size 4.8 kB
Tags Source
SHA-256 checksum
How to use checksums
aa86dfce27e01ac0c79ff122ac25bf35a36d22bb0806c73f528dbf2fce5d89b4
BLAKE2b-256 checksum
How to use checksums
668460ecc5235357e2d96c6530b1a99716d935f56ae31453530f7de115f2bb1d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.3.2 CPython/3.9.5 Darwin/22.2.0

Release files / et_stopwatch-1.2.2-py3-none-any.whl

Download URL et_stopwatch-1.2.2-py3-none-any.whl
Size 5.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1f44d63e030a9523a86acfdea6ea8544bdf2438c8b590ea01b9bc731c5137bcc
BLAKE2b-256 checksum
How to use checksums
406c53fb50f615de967df9de5704309239e04138f8f623a6d6fc71e897f839a0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.3.2 CPython/3.9.5 Darwin/22.2.0

Release history Release notifications | RSS feed

1.3.1

2 release files

1.3.0

2 release files

1.2.3

2 release files

This release

1.2.2 This release

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

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