From d7cef3443d890233d156b4da44b484788330e4c3 Mon Sep 17 00:00:00 2001 From: sas5188 <148003648+sas5188@users.noreply.github.com> Date: Mon, 18 May 2026 07:47:22 +0300 Subject: [PATCH] Create timer_murad_maharramli.py --- Week06/timer_murad_maharramli.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Week06/timer_murad_maharramli.py diff --git a/Week06/timer_murad_maharramli.py b/Week06/timer_murad_maharramli.py new file mode 100644 index 00000000..bc40b01f --- /dev/null +++ b/Week06/timer_murad_maharramli.py @@ -0,0 +1,24 @@ +import time + +class Timer: + """ + A context manager class that measures the execution time of a code block. + """ + def __init__(self): + # Initialize the required public attributes + self.start_time = None + self.end_time = None + + def __enter__(self): + # time.perf_counter() is used instead of time.time() for the highest + # available resolution when measuring short durations. + self.start_time = time.perf_counter() + return self + + def __exit__(self, exc_type, exc_val, exc_tb): + # Record the end time the moment the code block finishes + self.end_time = time.perf_counter() + + # Returning False ensures that if an exception occurs inside the 'with' block, + # it is not suppressed and raises normally. + return False