Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions Week06/timer_dilek_celebi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import time

class Timer:
"""
A context manager class to measure the time taken by a block of code.

Attributes:
start_time (float): The time when the context block started.
end_time (float): The time when the context block ended.
"""

def __enter__(self):
self.start_time = time.time() # Zaman ölçümünü başlat
return self

def __exit__(self, exc_type, exc_value, traceback):
self.end_time = time.time() # Zaman ölçümünü sonlandır
self.elapsed_time = self.end_time - self.start_time # Geçen süreyi hesapla

if __name__ == "__main__":
with Timer() as timer:
for i in range(1000000):
pass

print(f"Start time: {timer.start_time}")
print(f"End time: {timer.end_time}")
print(f"Elapsed time: {timer.elapsed_time} seconds")
Loading