Unverified 提交 bbfafeab authored 作者: Glenn Jocher's avatar Glenn Jocher 提交者: GitHub

Add `Profile()` profiler (#4587)

* Add `Profile()` profiler * CamelCase Timeout
上级 d7aa3f15
...@@ -39,8 +39,17 @@ cv2.setNumThreads(0) # prevent OpenCV from multithreading (incompatible with Py ...@@ -39,8 +39,17 @@ cv2.setNumThreads(0) # prevent OpenCV from multithreading (incompatible with Py
os.environ['NUMEXPR_MAX_THREADS'] = str(min(os.cpu_count(), 8)) # NumExpr max threads os.environ['NUMEXPR_MAX_THREADS'] = str(min(os.cpu_count(), 8)) # NumExpr max threads
class timeout(contextlib.ContextDecorator): class Profile(contextlib.ContextDecorator):
# Usage: @timeout(seconds) decorator or 'with timeout(seconds):' context manager # Usage: @Profile() decorator or 'with Profile():' context manager
def __enter__(self):
self.start = time.time()
def __exit__(self, type, value, traceback):
print(f'Profile results: {time.time() - self.start:.5f}s')
class Timeout(contextlib.ContextDecorator):
# Usage: @Timeout(seconds) decorator or 'with Timeout(seconds):' context manager
def __init__(self, seconds, *, timeout_msg='', suppress_timeout_errors=True): def __init__(self, seconds, *, timeout_msg='', suppress_timeout_errors=True):
self.seconds = int(seconds) self.seconds = int(seconds)
self.timeout_message = timeout_msg self.timeout_message = timeout_msg
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论