import time
# コンテキストマネージャを使ったシンプルなタイマー
class Timer:
def __enter__(self):
self.start = time.time()
return self
def __exit__(self, *args):
end = time.time()
print(f"実行時間: {end - self.start:.2f}秒")
# デモ実行
with Timer():
print("処理を開始します...")
time.sleep(5)
print("処理が完了しました!")
To embed this project on your website, copy the following code and paste it into your website's HTML: