Skip to content

Commit

Permalink
Adds a verbose input to Timer() constructor to guard printouts
Browse files Browse the repository at this point in the history
  • Loading branch information
peterdsharpe committed Jun 16, 2024
1 parent 7f5b849 commit f8b3f89
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions aerosandbox/tools/code_benchmarking.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ class Timer(object):
number_running: int = 0 # The number of Timers currently running

def __init__(self,
name: str = None
name: str = None,
verbose: bool = True,
):
self.name: str = name
self.verbose: bool = verbose
self.runtime: float = np.nan

def __repr__(self):
Expand All @@ -65,10 +67,11 @@ def _format_time(time_seconds):
return eng_string(time_seconds / u.year, unit="year")

def _print(self, s: str, number_running_mod: int = 0):
header = "\t" * (self.__class__.number_running - 1 + number_running_mod)
if self.name:
header += f"[{self.name}] "
print(header + s)
if self.verbose:
header = "\t" * (self.__class__.number_running - 1 + number_running_mod)
if self.name:
header += f"[{self.name}] "
print(header + s)

def tic(self):
self.__class__.number_running += 1
Expand Down

0 comments on commit f8b3f89

Please sign in to comment.