stopwatch.py 915 B

12345678910111213141516171819202122232425262728293031
  1. """Deprecated Stopwatch implementation"""
  2. # Copyright (c) PyZMQ Development Team.
  3. # Distributed under the terms of the Modified BSD License.
  4. class Stopwatch(object):
  5. """Deprecated zmq.Stopwatch implementation
  6. You can use Python's builtin timers (time.monotonic, etc.).
  7. """
  8. def __init__(self):
  9. import warnings
  10. warnings.warn("zmq.Stopwatch is deprecated. Use stdlib time.monotonic and friends instead",
  11. DeprecationWarning, stacklevel=2,
  12. )
  13. self._start = 0
  14. import time
  15. try:
  16. self._monotonic = time.monotonic
  17. except AttributeError:
  18. self._monotonic = time.time
  19. def start(self):
  20. """Start the counter"""
  21. self._start = self._monotonic()
  22. def stop(self):
  23. """Return time since start in microseconds"""
  24. stop = self._monotonic()
  25. return int(1e6 * (stop - self._start))