Skip to content

Instantly share code, notes, and snippets.

@TeraBytesMemory
Created June 17, 2023 05:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TeraBytesMemory/e67435e66ac742ea1d193b14ce8c59e4 to your computer and use it in GitHub Desktop.
Save TeraBytesMemory/e67435e66ac742ea1d193b14ce8c59e4 to your computer and use it in GitHub Desktop.
pythonでwith context内での実行の実行時間を計測するスクリプト
# 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