MCPcopy Create free account
hub / github.com/tensorpack/tensorpack / Timer

Class Timer

tensorpack/utils/timer.py:113–155  ·  view source on GitHub ↗

A timer class which computes the time elapsed since the start/reset of the timer.

Source from the content-addressed store, hash-verified

111
112
113class Timer():
114 """
115 A timer class which computes the time elapsed since the start/reset of the timer.
116 """
117 def __init__(self):
118 self.reset()
119
120 def reset(self):
121 """
122 Reset the timer.
123 """
124 self._start = timer()
125 self._paused = False
126 self._total_paused = 0
127
128 def pause(self):
129 """
130 Pause the timer.
131 """
132 assert self._paused is False
133 self._paused = timer()
134
135 def is_paused(self):
136 return self._paused is not False
137
138 def resume(self):
139 """
140 Resume the timer.
141 """
142 assert self._paused is not False
143 self._total_paused += timer() - self._paused
144 self._paused = False
145
146 def seconds(self):
147 """
148 Returns:
149 float: the total number of seconds since the start/reset of the timer, excluding the
150 time in between when the timer is paused.
151 """
152 if self._paused:
153 self.resume()
154 self.pause()
155 return timer() - self._start - self._total_paused

Callers 2

benchmark_serializerFunction · 0.90
__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…