Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/zmq/sugar/stopwatch.py: 35%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""Deprecated Stopwatch implementation"""
3# Copyright (c) PyZMQ Development Team.
4# Distributed under the terms of the Modified BSD License.
7class Stopwatch:
8 """Deprecated zmq.Stopwatch implementation
10 You can use Python's builtin timers (time.monotonic, etc.).
11 """
13 _start: float
15 def __init__(self) -> None:
16 import warnings
18 warnings.warn(
19 "zmq.Stopwatch is deprecated. Use stdlib time.monotonic and friends instead",
20 DeprecationWarning,
21 stacklevel=2,
22 )
23 self._start = 0
24 import time
26 try:
27 self._monotonic = time.monotonic
28 except AttributeError:
29 self._monotonic = time.time
31 def start(self) -> None:
32 """Start the counter"""
33 self._start = self._monotonic()
35 def stop(self) -> int:
36 """Return time since start in microseconds"""
37 stop = self._monotonic()
38 return int(1e6 * (stop - self._start))