Skip to content

Commit

Permalink
Make a global timer object for timing across modules.
Browse files Browse the repository at this point in the history
  • Loading branch information
markmuetz committed Sep 27, 2023
1 parent a640ae5 commit 67f70a0
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions remake/loop_timer.py → remake/global_timer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
from tabulate import tabulate


class LoopTimer:
def __init__(self):
class GlobalTimer:
global_timers = {}

def __init__(self, name):
self.name = name
self.timers = defaultdict(list)
self.last_time = None
self.curr_key = None
Expand All @@ -29,4 +32,14 @@ def __str__(self):
time_mean_ms = np.mean(times_ms)
time_std_ms = np.std(times_ms)
output.append((f'{k1} -> {k2}', f'{time_mean_ms / 1e6:.2g}s', f'(+/- {time_std_ms / 1e6:.2g}s)'))
return tabulate(output, headers=('tx', 'mean', 'std'))
return f'{self.name}\n' + tabulate(output, headers=('tx', 'mean', 'std'))


def get_global_timer(name):
if name in GlobalTimer.global_timers:
return GlobalTimer.global_timers[name]
else:
global_timer = GlobalTimer(name)
GlobalTimer.global_timers[name] = global_timer
return global_timer

0 comments on commit 67f70a0

Please sign in to comment.