Skip to content

Migrate from tic,tac,toc timers to new Timer context manager in the quantecon package #390

Closed

Description

@mmcky

We will soon release a new version of the quantecon package with a new Timer context manager.

Details of the implementation can be found here: QuantEcon/QuantEcon.py#783 (review)

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.

Activity

  1. mmcky commented on Aug 17, 2025

    @mmcky
    ContributorAuthor

    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:

    1. convert to simple timing (i..e time once) and check the context of the lecture remains in tact re: discussion
    2. update qe.Timer() to enable a runs= parameter and we could compute an average time to support similar numbers.
  2. jstac commented on Aug 17, 2025

    @jstac
    Contributor

    I favor option 2 @mmcky . It's the kind of functionality people will want in a timer. Thanks

  3. mmcky commented on Aug 26, 2025

    @mmcky
    ContributorAuthor
  4. mmcky commented on Aug 27, 2025

    @mmcky
    ContributorAuthor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions