Skip to content

Commit 58f397d

Browse files
Copilotmmcky
andcommitted
Revert tic/tac/toc/loop_timer to original defaults - keep only Timer and timeit using global precision
Co-authored-by: mmcky <[email protected]>
1 parent bc95427 commit 58f397d

File tree

2 files changed

+26
-39
lines changed

2 files changed

+26
-39
lines changed

quantecon/util/tests/test_timing.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -360,28 +360,27 @@ def test_timer_explicit_precision_overrides_global(self):
360360
timer = Timer(precision=3, verbose=False)
361361
assert timer.precision == 3
362362

363-
def test_tac_toc_use_global_precision(self):
364-
"""Test that tac/toc functions use global precision by default."""
365-
# This is harder to test automatically since it affects output formatting
366-
# But we can verify the functions accept None for digits parameter
367-
qe.timings.float_precision(6)
368-
363+
def test_tac_toc_keep_original_defaults(self):
364+
"""Test that tac/toc functions maintain original default (digits=2)."""
365+
# These functions are deprecated and should maintain original behavior
369366
tic()
370367
time.sleep(0.01)
371368

372-
# These should use global precision (no exception means it works)
373-
tac(verbose=False, digits=None)
374-
toc(verbose=False, digits=None)
369+
# These should use digits=2 by default, not global precision
370+
result_tac = tac(verbose=False) # Uses default digits=2
371+
result_toc = toc(verbose=False) # Uses default digits=2
372+
373+
# Just verify they work without error
374+
assert result_tac > 0
375+
assert result_toc > 0
375376

376-
def test_loop_timer_uses_global_precision(self):
377-
"""Test that loop_timer uses global precision by default."""
377+
def test_loop_timer_keeps_original_default(self):
378+
"""Test that loop_timer maintains original default (digits=2)."""
378379
def test_func():
379380
time.sleep(0.001)
380381

381-
qe.timings.float_precision(6)
382-
383-
# Should use global precision without error
384-
result = loop_timer(2, test_func, digits=None, verbose=False)
382+
# Should use digits=2 by default, not global precision
383+
result = loop_timer(2, test_func, verbose=False)
385384
assert len(result) == 2 # Returns (average_time, average_of_best)
386385

387386
def test_timeit_uses_global_precision(self):

quantecon/util/timing.py

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def tic(self):
4040
self.start = t
4141
self.last = t
4242

43-
def tac(self, verbose=True, digits=None):
43+
def tac(self, verbose=True, digits=2):
4444
"""
4545
Return and print elapsed time since last `tic()`, `tac()`, or
4646
`toc()`.
@@ -50,9 +50,8 @@ def tac(self, verbose=True, digits=None):
5050
verbose : bool, optional(default=True)
5151
If True, then prints time.
5252
53-
digits : scalar(int), optional(default=None)
54-
Number of digits printed for time elapsed. If None, uses
55-
the global default precision from quantecon.timings.
53+
digits : scalar(int), optional(default=2)
54+
Number of digits printed for time elapsed.
5655
5756
Returns
5857
-------
@@ -63,9 +62,6 @@ def tac(self, verbose=True, digits=None):
6362
if self.start is None:
6463
raise Exception("tac() without tic()")
6564

66-
if digits is None:
67-
digits = get_default_precision()
68-
6965
t = time.time()
7066
elapsed = t-self.last
7167
self.last = t
@@ -78,7 +74,7 @@ def tac(self, verbose=True, digits=None):
7874

7975
return elapsed
8076

81-
def toc(self, verbose=True, digits=None):
77+
def toc(self, verbose=True, digits=2):
8278
"""
8379
Return and print time elapsed since last `tic()`.
8480
@@ -87,9 +83,8 @@ def toc(self, verbose=True, digits=None):
8783
verbose : bool, optional(default=True)
8884
If True, then prints time.
8985
90-
digits : scalar(int), optional(default=None)
91-
Number of digits printed for time elapsed. If None, uses
92-
the global default precision from quantecon.timings.
86+
digits : scalar(int), optional(default=2)
87+
Number of digits printed for time elapsed.
9388
9489
Returns
9590
-------
@@ -100,9 +95,6 @@ def toc(self, verbose=True, digits=None):
10095
if self.start is None:
10196
raise Exception("toc() without tic()")
10297

103-
if digits is None:
104-
digits = get_default_precision()
105-
10698
t = time.time()
10799
self.last = t
108100
elapsed = t-self.start
@@ -115,7 +107,7 @@ def toc(self, verbose=True, digits=None):
115107

116108
return elapsed
117109

118-
def loop_timer(self, n, function, args=None, verbose=True, digits=None,
110+
def loop_timer(self, n, function, args=None, verbose=True, digits=2,
119111
best_of=3):
120112
"""
121113
Return and print the total and average time elapsed for n runs
@@ -135,9 +127,8 @@ def loop_timer(self, n, function, args=None, verbose=True, digits=None,
135127
verbose : bool, optional(default=True)
136128
If True, then prints average time.
137129
138-
digits : scalar(int), optional(default=None)
139-
Number of digits printed for time elapsed. If None, uses
140-
the global default precision from quantecon.timings.
130+
digits : scalar(int), optional(default=2)
131+
Number of digits printed for time elapsed.
141132
142133
best_of : scalar(int), optional(default=3)
143134
Average time over best_of runs.
@@ -151,9 +142,6 @@ def loop_timer(self, n, function, args=None, verbose=True, digits=None,
151142
Average of best_of times for n runs of function.
152143
153144
"""
154-
if digits is None:
155-
digits = get_default_precision()
156-
157145
tic()
158146
all_times = np.empty(n)
159147
for run in range(n):
@@ -456,15 +444,15 @@ def tic():
456444
return __timer__.tic()
457445

458446

459-
def tac(verbose=True, digits=None):
447+
def tac(verbose=True, digits=2):
460448
return __timer__.tac(verbose, digits)
461449

462450

463-
def toc(verbose=True, digits=None):
451+
def toc(verbose=True, digits=2):
464452
return __timer__.toc(verbose, digits)
465453

466454

467-
def loop_timer(n, function, args=None, verbose=True, digits=None, best_of=3):
455+
def loop_timer(n, function, args=None, verbose=True, digits=2, best_of=3):
468456
return __timer__.loop_timer(n, function, args, verbose, digits, best_of)
469457

470458

0 commit comments

Comments
 (0)