step_timing
StepTimer
¶
Source code in /usr/src/app/checkouts/readthedocs.org/user_builds/european-xfel-offline-calibration/envs/latest/lib/python3.8/site-packages/cal_tools/step_timing.py
class StepTimer:
def __init__(self):
self.steps = defaultdict(list)
self.t0 = None
self.t_latest = None
def start(self):
"""Store a start timestamp"""
t = perf_counter()
if self.t0 is None:
self.t0 = t
self.t_latest = t
def done_step(self, step_name):
"""Record a step timing, since the last call to done_step() or start()
"""
t = perf_counter()
self.steps[step_name].append(t - self.t_latest)
print(f"{step_name}: {t - self.t_latest:.01f} s")
self.t_latest = t
def timespan(self):
"""Wall time from 1st call to start() to last start() or done_step()"""
if self.t_latest is not None and self.t0 is not None:
return self.t_latest - self.t0
else:
return 0
def print_summary(self):
"""Show mean & std for each step"""
for step, data in self.steps.items():
data = np.asarray(data)
print(f'{step}: {data.mean():.01f} +- {data.std():.02f} s')
done_step(step_name)
¶
Record a step timing, since the last call to done_step() or start()
Source code in /usr/src/app/checkouts/readthedocs.org/user_builds/european-xfel-offline-calibration/envs/latest/lib/python3.8/site-packages/cal_tools/step_timing.py
print_summary()
¶
Show mean & std for each step
Source code in /usr/src/app/checkouts/readthedocs.org/user_builds/european-xfel-offline-calibration/envs/latest/lib/python3.8/site-packages/cal_tools/step_timing.py
start()
¶
Store a start timestamp
timespan()
¶
Wall time from 1st call to start() to last start() or done_step()