-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
INFR: Add Timer context manager for modern timing patterns #783
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@mmcky 👋 This repository doesn't have Copilot instructions. With Copilot instructions, I can understand the repository better, work faster and produce higher quality PRs. I can generate a .github/copilot-instructions.md file for you automatically. Click here to open a pre-filled issue and assign it to me. I'll write the instructions, and then tag you for review. |
Co-authored-by: mmcky <[email protected]>
This is an example of use within a lecture from ![]() @jstac I quite like this style and the functionality that for comparison here is our existing ![]() |
|
This is really nice @mmcky :-) I'm happy for you to go ahead. It will be really nice to get these changes propagated... |
thanks @jstac. I will double check the code and get this merged.
Note (@jstac): from a style perspective do you prefer this approach for timing code to using Jupyter cell magics As I see it the main downside is ![]() |
I have usecases of |
Fully agree @oyamad. We are in no real rush to remove them, but I was thinking about issuing a DeprecationWarning with links to a migration guide -- perhaps in the next major release. #783 (comment) includes the pattern, but including in the notice is always helpful. Given we have an open issue (See #786) -- I will check that box off and we can treat that separately. @oyamad I have updated the QuantEcon manual with some more information https://manual.quantecon.org/styleguide/code.html#performance-timing-patterns |
This PR implements a
Timer
context manager to modernize timing patterns in QuantEcon.py, addressing the infrastructure need identified in the issue.Problem
The codebase currently uses manual timing patterns like:
This approach is verbose and error-prone, requiring manual time calculations and formatting.
Solution
Added a
Timer
context manager that provides clean, modern timing syntax:Features
timer.elapsed
after context exit for performance comparisonsImplementation Details
Timer
class to existingquantecon/util/timing.py
modulequantecon.Timer
andquantecon.util.Timer
tic
/tac
/toc
functionsUsage Examples
The Timer supports various usage patterns:
Fixes #782.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.