You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Migrate from tic,tac,toc timers to new Timer context manager in the quantecon package #390
We need to go through the lectures updating any tic, tac, toc timing comparisons to the new Timer
We also need to review the surrounding text to make sure the timing comparisons are still relevant. For example, the next sometimes discusses a certain code-cell runs X times faster than another, so we should check that logic still works after we migrate to Timer.
In PR #391 we have migrated tic, tac, toc and %time to make use of the new context manager.
However, %timeit has different behaviour in that is samples x number of runs to get an average time.
@jstac do you remember the main reason for using %timeit vs %time -- I think it often related to relatively small run times and the %timeit gave a more consistent result.
I see two ways to address this:
convert to simple timing (i..e time once) and check the context of the lecture remains in tact re: discussion
update qe.Timer() to enable a runs= parameter and we could compute an average time to support similar numbers.
There are limitations around how context managers work -- We can't loop over the context, so it is hard to just add a runs= parameter to a context manager. After some iteration, I have gone with a separate timeit function from the qe library to replace %%timeit that will loop over our context manager.
Activity
mmcky commentedon Aug 17, 2025
In PR #391 we have migrated
tic,tac,tocand%timeto make use of the new context manager.However,
%timeithas different behaviour in that is samplesxnumber of runs to get an average time.@jstac do you remember the main reason for using
%timeitvs%time-- I think it often related to relatively small run times and the%timeitgave a more consistent result.I see two ways to address this:
qe.Timer()to enable aruns=parameter and we could compute an average time to support similar numbers.jstac commentedon Aug 17, 2025
I favor option 2 @mmcky . It's the kind of functionality people will want in a timer. Thanks
mmcky commentedon Aug 26, 2025
Thanks @jstac -- QuantEcon/QuantEcon.py#794
mmcky commentedon Aug 27, 2025
There are limitations around how context managers work -- We can't loop over the context, so it is hard to just add a
runs=parameter to a context manager. After some iteration, I have gone with a separatetimeitfunction from theqelibrary to replace%%timeitthat will loop over our context manager.