Skip to content

Commit

Permalink
Add Profile() profiler (ultralytics#4587)
Browse files Browse the repository at this point in the history
* Add `Profile()` profiler

* CamelCase Timeout
  • Loading branch information
glenn-jocher authored and CesarBazanAV committed Sep 29, 2021
1 parent c81873c commit 531f4e3
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions utils/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,17 @@
os.environ['NUMEXPR_MAX_THREADS'] = str(min(os.cpu_count(), 8)) # NumExpr max threads


class timeout(contextlib.ContextDecorator):
# Usage: @timeout(seconds) decorator or 'with timeout(seconds):' context manager
class Profile(contextlib.ContextDecorator):
# 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):
self.seconds = int(seconds)
self.timeout_message = timeout_msg
Expand Down

0 comments on commit 531f4e3

Please sign in to comment.