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

17 statements  

1"""Deprecated Stopwatch implementation""" 

2 

3# Copyright (c) PyZMQ Development Team. 

4# Distributed under the terms of the Modified BSD License. 

5 

6 

7class Stopwatch: 

8 """Deprecated zmq.Stopwatch implementation 

9 

10 You can use Python's builtin timers (time.monotonic, etc.). 

11 """ 

12 

13 _start: float 

14 

15 def __init__(self) -> None: 

16 import warnings 

17 

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 

25 

26 try: 

27 self._monotonic = time.monotonic 

28 except AttributeError: 

29 self._monotonic = time.time 

30 

31 def start(self) -> None: 

32 """Start the counter""" 

33 self._start = self._monotonic() 

34 

35 def stop(self) -> int: 

36 """Return time since start in microseconds""" 

37 stop = self._monotonic() 

38 return int(1e6 * (stop - self._start))