Skip to content

Replace deprecated tic/toc timers with qe.Timer in kesten_processes #329

Description

@mmcky

Summary

quantecon is deprecating the Matlab-like timers tic / tac / toc / loop_timer in favour of the Timer context manager and timeit. See QuantEcon/QuantEcon.py#833, which adds a DeprecationWarning to these functions (removal targeted for a later release). lectures/kesten_processes.md is the only lecture across the Python family still using them, so once the deprecation ships its build output will start emitting warnings.

Where it's used

lectures/kesten_processes.md imports and calls the deprecated API:

  • Import: from quantecon import tic, toc (around line 59) — can be dropped, since the file already does import quantecon as qe (line 54).
  • Six tic()toc() pairs around lines 238/240, 246/248, 317/319, 323/325, 396/398, and 402/404.

Suggested change

Each block wraps a single call and just prints elapsed time, so it maps cleanly onto the Timer context manager (which prints on exit, exactly like toc()):

# before
tic()
data = generate_cross_section(firm).block_until_ready()
toc()

# after
with qe.Timer():
    data = generate_cross_section(firm).block_until_ready()

All six pairs follow the identical shape, so this is a mechanical swap. Optionally, a label can be passed to distinguish the with-compile vs without-compile runs, e.g. qe.Timer("with JIT compile").

Notes

  • No uses of tac or loop_timer anywhere in the lecture, so nothing else needs porting.
  • The upstream deprecation PR is still open, so there is no urgency — this just future-proofs the lecture and keeps its build output warning-free.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueSelf-contained and friendly to newcomers

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions