Skip to content

Commit bede9b9

Browse files
committed
Refine the definition of the toc() delta argument
1 parent f555047 commit bede9b9

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

pyomo/common/tests/test_timing.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def test_TicTocTimer_tictoc(self):
168168
with capture_output() as out:
169169
ref = time.perf_counter()
170170
total = timer.toc(delta=False)
171-
self.assertAlmostEqual(ref - abs_time, total, delta=RES)
171+
self.assertAlmostEqual(ref - start_time, total, delta=RES)
172172
self.assertRegex(
173173
out.getvalue(),
174174
r'\[ [.0-9]+\] .* in test_TicTocTimer_tictoc'

pyomo/common/timing.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ def tic(self, msg=_NotSpecified,
205205
class was constructed). Note: timing logged using logger.info
206206
207207
"""
208-
self._lastTime = default_timer()
208+
self._lastTime = self._loadTime = default_timer()
209209
if msg is _NotSpecified:
210210
msg = "Resetting the tic/toc delta timer"
211211
if msg is not None:
@@ -225,9 +225,9 @@ def toc(self, msg=_NotSpecified, delta=True,
225225
called this method; if msg is None, then no message is
226226
printed.
227227
delta (bool): print out the elapsed wall clock time since
228-
the last call to :meth:`tic` or :meth:`toc`
229-
(``True`` (default)) or since the module was first
230-
loaded (``False``).
228+
the last call to :meth:`tic` (``False``) or since the
229+
most recent call to either :meth:`tic` or :meth:`toc`
230+
(``True`` (default)).
231231
ostream (FILE): an optional output stream (overrides the ostream
232232
provided when the class was constructed).
233233
logger (Logger): an optional output stream using the python
@@ -254,6 +254,9 @@ class was constructed). Note: timing logged using logger.info
254254
msg = "[+%7.2f] %s\n" % (ans, msg)
255255
else:
256256
ans = now - self._loadTime
257+
# Even though we are reporting the cumulative time, we will
258+
# still reset the delta timer.
259+
self._lastTime = now
257260
if msg is not None:
258261
msg = "[%8.2f] %s\n" % (ans, msg)
259262

0 commit comments

Comments
 (0)