-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Closed
Description
There are a lot of code patterns that use a timer such as
start_time = time()
freq = compute_freq(params, key).block_until_ready()
end_time = time()
print(f"Elapsed time: {(end_time - start_time) * 1000:.6f} ms")
We could modernise the QuantEcon timer by writing a simple context manager such as
import time
class Timer:
def __enter__(self):
self._enter_time = time.time()
def __exit__(self, *exc_args):
self._exit_time = time.time()
print(f"{self._exit_time - self._enter_time:.2f} seconds elapsed")
if __name__ == "__main__":
with Timer():
# ...
that would print the time elapsed using a context manager.
Copilot
Metadata
Metadata
Labels
No labels
Type
Projects
Status
Done