From e2d957b5eeac651e1dc984319ab2527f5faebee2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Eekip=20Yaman=20Arslan?= <155294621+yamanarslan@users.noreply.github.com> Date: Tue, 7 Apr 2026 21:38:47 +0300 Subject: [PATCH] Add Timer context manager class Implement a Timer context manager for measuring execution time. --- Week06/timer_sekip_yaman_arslan.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Week06/timer_sekip_yaman_arslan.py diff --git a/Week06/timer_sekip_yaman_arslan.py b/Week06/timer_sekip_yaman_arslan.py new file mode 100644 index 00000000..1302153d --- /dev/null +++ b/Week06/timer_sekip_yaman_arslan.py @@ -0,0 +1,20 @@ +import time + + +class Timer: + """ + A context manager class that measures the time taken + by the block of code it manages. + """ + + def __init__(self): + self.start_time = None + self.end_time = None + + def __enter__(self): + self.start_time = time.time() + return self + + def __exit__(self, exc_type, exc_val, exc_tb): + self.end_time = time.time() + return False