Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.10/site-packages/zmq/sugar/stopwatch.py: 27%

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

15 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 def __init__(self): 

14 import warnings 

15 

16 warnings.warn( 

17 "zmq.Stopwatch is deprecated. Use stdlib time.monotonic and friends instead", 

18 DeprecationWarning, 

19 stacklevel=2, 

20 ) 

21 self._start = 0 

22 import time 

23 

24 try: 

25 self._monotonic = time.monotonic 

26 except AttributeError: 

27 self._monotonic = time.time 

28 

29 def start(self): 

30 """Start the counter""" 

31 self._start = self._monotonic() 

32 

33 def stop(self): 

34 """Return time since start in microseconds""" 

35 stop = self._monotonic() 

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