Created
June 17, 2023 05:35
-
-
Save TeraBytesMemory/e67435e66ac742ea1d193b14ce8c59e4 to your computer and use it in GitHub Desktop.
pythonでwith context内での実行の実行時間を計測するスクリプト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# with context内での実行の実行時間を計測するスクリプト | |
import time | |
class ElapseTimeInWithContext(object): | |
def __init__(self, context): | |
self.context = context | |
def __enter__(self): | |
self.start = time.time() | |
return self | |
def __exit__(self, *args): | |
print(f"{self.context} elapsed time (msec): {1000 * (time.time() - self.start)}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment