You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

timer.py 934 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. """
  4. Created on Mon Mar 23 09:52:50 2020
  5. @author: ljia
  6. """
  7. import time
  8. class Timer(object):
  9. """A timer class that can be used by methods that support time limits.
  10. Note
  11. ----
  12. This is the Python implementation of `the C++ code in GEDLIB <https://github.com/dbblumenthal/gedlib/blob/master/src/env/timer.hpp>`__.
  13. """
  14. def __init__(self, time_limit_in_sec):
  15. """Constructs a timer for a given time limit.
  16. Parameters
  17. ----------
  18. time_limit_in_sec : string
  19. The time limit in seconds.
  20. """
  21. self.__time_limit_in_sec = time_limit_in_sec
  22. self.__start_time = time.time()
  23. def expired(self):
  24. """Checks if the time limit has expired.
  25. Return
  26. ------
  27. Boolean true if the time limit has expired and false otherwise.
  28. """
  29. if self.__time_limit_in_sec > 0:
  30. runtime = time.time() - self.__start_time
  31. return runtime >= self.__time_limit_in_sec
  32. return False

A Python package for graph kernels, graph edit distances and graph pre-image problem.