Skip to content

Commit

Permalink
fix the issue that time.clock() method no longer exists in higher v…
Browse files Browse the repository at this point in the history
…ersion of python, and close #30
  • Loading branch information
tangypnuaa authored and tangypnuaa committed Mar 1, 2021
1 parent 859cc18 commit 57f5a1e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions alipy/experiment/stopping_criteria.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def __init__(self, stopping_criteria=None, value=None):
if not isinstance(value, float) and value is not None:
value = float(value)
if stopping_criteria == 'time_limit':
self._start_time = time.clock()
self._start_time = time.perf_counter()
self.value = value

# collect information
Expand Down Expand Up @@ -102,7 +102,7 @@ def is_stop(self):
else:
return False
elif self._stopping_criteria == 'time_limit':
if time.clock() - self._start_time >= self.value:
if time.perf_counter() - self._start_time >= self.value:
return True
else:
return False
Expand Down Expand Up @@ -132,7 +132,7 @@ def reset(self):
Reset the current state to the initial.
"""
self.value = self._init_value
self._start_time = time.clock()
self._start_time = time.perf_counter()
self._current_iter = 0
self._accum_cost = 0
self._current_unlabel = 100
Expand Down
6 changes: 3 additions & 3 deletions alipy/utils/multi_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def __init__(self, examples, labels, train_idx, test_idx, label_index, unlabel_i
assert max_thread > 0
self.__max_thread = max_thread
# for controlling the print frequency
self._start_time = time.clock()
self._start_time = time.perf_counter()
# for displaying the time elapse
self._thread_time_elapse = [-1] * self._round_num
# for recovering the workspace
Expand Down Expand Up @@ -246,8 +246,8 @@ def __repr__(self):
return str(tb)

def _if_refresh(self):
if time.clock() - self._start_time > self._refresh_interval:
self._start_time = time.clock()
if time.perf_counter() - self._start_time > self._refresh_interval:
self._start_time = time.perf_counter()
return True
else:
return False
Expand Down

0 comments on commit 57f5a1e

Please sign in to comment.